如何使用 php 中的预准备语句从 mysql 数据库中检索数据


How to retrieve data from the mysql database using prepared statement in php?

<?php
    require "config.php";
    if($stmt = $mysqli -> prepare("SELECT * FROM donorregistration WHERE Email=? and Password=?")) 
    {
        $email=$_POST['donorEmail'];
        $password=$_POST['password'];
        $stmt -> bind_param("ss",$email,$password);
        $stmt -> execute();
        $stmt->store_result();
        if($stmt->num_rows!=1)
        {
            echo "Sorry, Your E-mail ID or Password is incorrect";
        }
        else
        {
        }
    }
    $mysqli -> close();
?>

我不知道在 else 部分写什么。 我想从 mysql 数据库中打印名为"Account_Number"的列和名为"名称"的列。请帮助我。

使用 fetchbind_result 语句检索数据

在下面试试这个

<?php
require "config.php";
if($stmt = $mysqli -> prepare("SELECT * FROM donorregistration WHERE Email=? and Password=?")) 
{
    $email=$_POST['donorEmail'];
    $password=$_POST['password'];
    $stmt -> bind_param("ss",$email,$password);
    $stmt -> execute();
    $stmt->store_result();
    $stmt->bind_result($email,$pass);
    $stmt->fetch();
    if($stmt->num_rows!=1)
    {
        echo "Sorry, Your E-mail ID or Password is incorrect";
    }
    else
    {
        //retrieved 
       echo "Your email is $email and pass $pass");
    }
}
$mysqli -> close();

?>