2011-07-21 24 views
0

我試圖教自己PHP & MySQL。請注意我對此很新。以下是我收到的錯誤消息和所有代碼。致命錯誤:調用未定義的函數get_all_subjects()

我希望這是有道理的!

致命錯誤:調用未定義的函數get_all_subjects()在/Users/darren/Sites/widget_corp/content.php第9行

content.php代碼

<?php require_once("includes/connection.php"); ?> 
<?php require_once("includes/functions.php"); ?> 
<?php include("includes/header.php"); ?> 
<table id="structure"> 
<tr> 
<td id="navigation"> 
<ul class="subjects"> 
<?php 
$subject_set = get_all_subjects(); **// this is the problem line** 
while ($subject = mysql_fetch_array($subject_set)) { 
echo "<li><a href=\"content.php?subj=" . urlencode($subject["id"]) . 
    "\">{$subject["menu_name"]}</a></li>"; 
$page_set = get_pages_for_subject($subject["id"]); 
echo "<ul class=\"pages\">"; 
while ($page = mysql_fetch_array($page_set)) { 
    echo "<li><a href=\"content.php?page=" . urlencode($page["id"]) . 
     "\">{$page["menu_name"]}</a></li>"; 
} 
echo "</ul>"; 
} 

?> 
</ul> 
</td> 
<td id="page"> 
<h2>Content Area</h2> 

</td> 
</tr> 
</table> 
<?php require("includes/footer.php"); ?> 

這是我的功能代碼它位於名爲「includes」的文件夾中

</php 
// This is where we store all the basic functions 

function confirm_query($result_set) { 
if (!$result_set) { 
die("Database selection failed: " . mysql_error()); 
}  
} 

function get_all_subjects() { 
global $connection; 
$query = "SELECT * 
FROM subjects 
ORDER BY position ASC"; 
$subject_set = mysql_query($query, $connection); 
confirm_query($subject_set); 
return $subject_set; 
} 

function get_pages_for_subject($subject_id) { 
global $connection; 
$query = "SELECT * 
FROM pages 
WHERE subject_id = {$subject_id"} 
ORDER BY position ASC";    
$page_set = mysql_query($query, $connection); 
confirm_query($page_set); 
return $page_set; 
} 
?> 
+1

那是真正的

回答

6

您的功能代碼有一個錯誤形式的開頭<?php標籤 - 您有</php。如果沒有這個開始標記,PHP將以純文本的形式處理該文件,並且不會將其視爲PHP代碼。這意味着你的功能從未被定義。

請記住,沒有「PHP腳本」之類的東西。只有文本文件纔會包含PHP代碼塊。開頭<?PHP標籤在文件的某個位置是必需的,否則你的'代碼'就是文本。

+0

我是多麼愚蠢。謝謝你的幫助 –

相關問題