我收到以下错误消息
致命错误:调用未定义 函数get_subject_by_id()in /hsphere/local/home/c263430/prupt.com/content.php 第25行
这是第25行的功能
$sel_subject = get_subject_by_id($sel_subj);
这是它所指的功能。如何在错误消息中说明“未定义”?有人可以帮忙吗?
function get_subject_by_id($subject_id) {
global $connection;
$query = "SELECT * ";
$query .= "FROM subjects ";
$query .= "WHERE id='" . mysql_real_escape_string($subject_id) ."' ";
// note the quotes and escaping wrapper
$query .= "LIMIT 1";
$result_set = mysql_query($query, $connection);
confirm_query($result_set);
// if no rows are returned, fetch array will return false
if ($subject = mysql_fetch_array($result_set)) {
return $subject;
} else {
return NULL;
}
}
以下是调用该函数的页面的整个代码
<?php
//1.Create a database connection
$connection = mysql_connect("98.130.0.87", "User", "Pass");
if (!$connection) {
die("Database connection failed: " . mysql_error());
}
$db_select = mysql_select_db("C263430_testorwallo" ,$connection);
if (!$db_select) {
die("Database selection failed: " . mysql_error());
}
?>
<?php
if (isset($_GET['subj'])){
$sel_subject = get_subject_by_id($_GET['subj']);
$sel_pg = 0;
$sel_page = NULL;
} elseif (isset($_GET['page'])) {
$sel_subject = NULL;
$sel_page = get_page_by_id($_GET['page']);
} else {
$sel_subject = NULL;
$sel_page = NULL;
}
?>
<?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();
while ($subject = mysql_fetch_array($subject_set)){
echo "<li ";
if ($subject["id"] == $sel_subject['id']) {
echo " class=\"selected\"";
}
echo "><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";
if ($page["id"] == $sel_page['id']) {
echo " class=\"selected\"";
}
echo "><a href=\"content.php?page=" . urlencode($page["id"]) . "\">{$page["menu_name"]}</a></li>";
}
echo"</ul>";
}
?>
</ul>
</td>
<td id="page">
<?php if (!is_null($sel_subject)) {
<h2><?php echo $sel_subject['menu_name']; ?></h2>
<?php } else if (!is_null($sel_page)) {
<h2><?php echo $sel_page['menu_name]; ?></h2>
<?php } else {
<h2> Select a subject or page to edit </h2>
<?php } ?>
</td>
</tr>
</table>
<?php include("includes/footer.php"); ?>
答案 0 :(得分:3)
您在包含之前调用该函数。
在调用此函数之前,必须使用require_once。
<?php
require_once("includes/functions.php"); // include file here
if (isset($_GET['subj'])){
$sel_subject = get_subject_by_id($_GET['subj']);
$sel_pg = 0;
$sel_page = NULL;
} elseif (isset($_GET['page'])) {
$sel_subject = NULL;
$sel_page = get_page_by_id($_GET['page']);
} else {
$sel_subject = NULL;
$sel_page = NULL;
}
?>
答案 1 :(得分:0)
显然这已经得到了回答,但希望这会对其他人有所帮助。我遇到了同样的问题,这是因为不知何故x <?php
是我文件的第一行,而不是仅仅<?php
我更新了我的存储库。