dougaimian1143 2015-02-04 21:43
浏览 194
已采纳

警告:mysqli_fetch_array()期望参数1为mysqli_result,第32行给出布尔值[重复]

I have this error on my script. Although I'm unsure what it is. This code is to display ONLY the usersID's data from event. I haven't tried anything like this before, but this is my first approach from using session ID to define the users events.

  <?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);
?>
</div>
  • 写回答

1条回答 默认 最新

  • douze2890241475 2015-02-04 21:45
    关注

    You have a syntax error in your query.

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

    Last ' was missing, after userid stuff. Everytime check if query is not null or false.

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 关于#java#的问题,请各位专家解答!
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型
  • ¥15 如何实现H5在QQ平台上的二次分享卡片效果?
  • ¥30 求解达问题(有红包)
  • ¥15 请解包一个pak文件