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 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化
  • ¥15 Mirare PLUS 进行密钥认证?(详解)
  • ¥15 物体双站RCS和其组成阵列后的双站RCS关系验证
  • ¥20 想用ollama做一个自己的AI数据库
  • ¥15 关于qualoth编辑及缝合服装领子的问题解决方案探寻
  • ¥15 请问怎么才能复现这样的图呀