我在这里遵循这个教程并尝试完全按照那里解释的那样做。我虽然收到了错误:
警告:mysqli_error()预计在第12行的/storage/content/37/191037/website.se/public_html/newsite/admin/perfis/index.php中只提供1个参数0
以下是代码:
<?php
session_start();
require_once "scripts/conector.php";
// Determine which page ID to use in our query below -----------------------------------------------------------------------------------
if (!$_GET['pid']) {
$pageid = '1';
} else {
$pageid = ereg_replace("[^0-9]", "", $_GET['pid']); // filter everything but numbers for security
}
// Query the body section for the proper page
$sqlCommand = "SELECT pagebody FROM pages WHERE id='$pageid' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$body = $row["pagebody"];
}
mysqli_free_result($query);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Query the module data for display ---------------------------------------------------------------------------------------------------------------
$sqlCommand = "SELECT modulebody FROM modules WHERE showing='1' AND name='footer' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$footer = $row["modulebody"];
}
mysqli_free_result($query);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Query the module data for display ---------------------------------------------------------------------------------------------------------------
$sqlCommand = "SELECT modulebody FROM modules WHERE showing='1' AND name='custom1' LIMIT 1";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$custom1 = $row["modulebody"];
}
mysqli_free_result($query);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
// Build Main Navigation menu and gather page data here -----------------------------------------------------------------------------
$sqlCommand = "SELECT id, linklabel FROM pages WHERE showing='1' ORDER BY id ASC";
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
$menuDisplay = '';
while ($row = mysqli_fetch_array($query)) {
$pid = $row["id"];
$linklabel = $row["linklabel"];
$menuDisplay .= '<a href="index.php?pid=' . $pid . '">' . $linklabel . '</a><br />';
}
mysqli_free_result($query);
//---------------------------------------------------------------------------------------------------------------------------------------------------------------
//mysqli_close($myConnection);
?>
<?php echo $menuDisplay; ?>
我不明白我做错了什么。数据库运行良好,我已手动插入数据并且它工作正常,我也使用相同的数据库来建立登录机制,它也正常工作。
有人能发现错误吗?
答案 0 :(得分:4)
更改
die (mysqli_error());
到
die('Error: ' . mysqli_error($myConnection));
查询中的
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
答案 1 :(得分:0)
尝试
mysqli_error($myConnection)
因为mysqli_error()需要链接标识符作为参数
有关详细信息,请参阅http://de3.php.net/mysqli_error