警告:mysqli_fetch_assoc()期望参数1为mysqli_result

时间:2015-11-24 19:12:39

标签: php mysql

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\xampp\htdocs\stock\edit_categorie.php on line 96
An Error Occured
SELECT * FROM categories WHERE id=29

当我想在表单中添加一些值时,我遇到了上述问题。我该如何解决这个问题?

这是我的代码:

<?php
    $con=mysqli_connect("Localhost","root","","stock");
    if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();}

   if($_GET['id']){
$query="SELECT * FROM categories WHERE id=$_GET[id]";
$result=mysql_query($query);
   $row=mysqli_fetch_assoc($result);

if (!$result) {
printf("An Error Occured %s\n",mysqli_error($con));
echo'<p>'.$query.'</P>';
exit();}}?>
     <form method="post" action="edit_categorie.php">
       <div class="form-group">
           <input type="text" class="form-control" name="categorie_name" value="<?php echo $row['name'];?>" >
       </div>
       <button type="submit" name="edit_cat" class="btn btn-primary">Update categorie</button>
   </form>
   <?php}?>

1 个答案:

答案 0 :(得分:0)

您对mysql_query($query)的呼叫失败,因此返回false。您不能将布尔值传递给mysqli_fetch_assoc。正如Rizier123在评论中所说,你不应该混合使用mysql和mysqli。