简体   繁体   中英

Fatal error in PHP function prepared statement

I am using prepared statement for login. The compiler is giving a fatal error in the store result function. It is not saving the row in the result that I want to show. I saw solutions but they are not working.

if($_SERVER["REQUEST_METHOD"]=="POST"){
    $sql = "SELECT * FROM login where email=? and password=?";
    $stmt= $conn->prepare($sql);

    $stmt->bind_param("ss", $_POST["email"],$_POST["password"]);
    $stmt->execute();

    //$res=$result->num_rows;
    $res=store_result();
    $row = mysqli_fetch_assoc($res);

    if ($stmt->num_rows>0) {

        // output data of each row

      while($row['admin_role']==1)
      {
        $_SESSION["email"]=$email;
        $_SESSION["id"]=$row['user_id'];
        header('Location: index.html');
        exit; 
      }
     } else {
       echo "0 results";
     }
 }

?>

According to the docs here and the error message you are getting the function name should be mysqli_store_result and not store_result .

You will also need to provide your connection variable which looking at your code above appears to be $conn so it would be:

mysqli_store_result($conn)

Alternatively I believe you could call it as a class method directly using your $conn variable as below:

$conn->store_result()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM