Please help me i get this error:

Warning: mysqli_fetch_assoc() expects parameter 1 to be mysqli_result, boolean given in C:\wamp\www\admin\includes\update.php on line 18

The way that the user is define at the start is

http://localhost/admin/edit.php?username

And This is my code:

<?php
if($_REQUEST['do']){
$user=$_REQUEST['user'];
$pass=$_REQUEST['pass'];
$email=$_REQUEST['email'];
$science=$_REQUEST['science'];
$dscience=$_REQUEST['dscience'];
$sql="UPDATE `users` SET user='$user' AND pass='$pass' AND email='' science='$science' dscience='$dscience' WHERE user='$user'";
$result = mysqli_query($cxn, $sql);

echo "Account Updated.";
}
?><?php
if(!$_REQUEST['do']){ 
$user=$_SERVER['QUERY_STRING'];
$sql="SLECT * FROM `users` WHERE user='$user'";
$result = mysqli_query($cxn, $sql);
$row = mysqli_fetch_assoc($result);
?>
<form id="login" name="login" method="post" action="<?php echo "".$_SERVER['PHP_SELF']."?update";  ?>">
  <p align="center">Username:
    <input type="text" name="user" id="user" value="<?php echo $row['user'] ?>"/>
  </p>
  <p align="center">Password:
    <input type="text" name="pass" id="pass" value="<?php echo $row['pass'] ?>"/>
  </p>

  <p align="center">Email:

<input type="text" name="email" id="email"value="<?php echo $row['email'] ?>" />
</p>
  <p align="center">Teacher 1:
    <input type="text" name="science" id="science" value="<?php echo $row['science'] ?>"/>
  </p>
  <p align="center">Teacher 2:
    <input type="text" name="dscience" id="dscience" value="<?php echo $row['dscience'] ?>"/>
  </p>
  <p align="center"><input type="hidden" name="do" value="update" />
    <input type="submit" name="do" id="do" value="Update" />
  </p>
</form>  <?php } ?>

Thanks For Future Answers

    If the query doesn't return any rows it will return false.

    But you have a bigger problem than that. You should make sure that you get any sql error outputted on the development server, that way you can make sure that you don't have sql errors. Something like this should do:

    $result = mysqli_query($cxn, $sql) or die(mysqli_error); 
    

    Oh, and read up on sql injection / database injection. If you are not safe against it your database will be compromized, it is only a matter of time before it happens.

      Looks like you have a typo.

      $sql="SLECT * FROM `users` WHERE user='$user'";
      

      SLECT should be SELECT

        Write a Reply...