警告:mysqli_fetch_array()要求参数1为mysqli_result,第32行给出布尔值

时间:2015-02-04 21:43:19

标签: php mysql session

我的脚本上有这个错误。虽然我不确定它是什么。此代码仅显示来自事件的usersID数据。我之前没有尝试过这样的事情,但这是我使用会话ID定义用户事件的第一种方法。

  <?php
    session_start();
if(!isset($_SESSION["user"]) or !is_array($_SESSION["user"]) or empty($_SESSION["user"])
)

      // redirect to index page if not superuser
header('Location: index.php');

?>
<?php
$con=mysqli_connect("localhost","root","Af2vaz93j68","pdo_ret");
// Check connection
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}

$result = mysqli_query($con,"SELECT * FROM event WHERE userid = '".$_SESSION["user"]["id"]."");

echo "<table border='1'>
<tr>
<th>name</th>
<th>about</th>
<th>website</th>
<th>userid</th>
<th>key</th>

</tr>";

while($row = mysqli_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['name'] . "</td>";
echo "<td>" . $row['about'] . "</td>";
echo "<td>" . $row['website'] . "</td>";
echo "<td>" . $row['userid'] . "</td>";
echo "<td>" . $row['key'] . "</td>";

echo "</tr>";
}
echo "</table>";

mysqli_close($con);
?>

1 个答案:

答案 0 :(得分:0)

您的查询中存在语法错误。

$result = mysqli_query($con,"SELECT * FROM event WHERE userid = '".$_SESSION["user"]["id"]."'");

最后&#39;在用户标识之后丢失了。每次检查查询是否不是nullfalse

现在if( !$result ) { /* Then dont run your code */ } else { /* run it */ }