变量数量与参数数量不匹配

时间:2016-06-04 16:00:57

标签: php mysql

我正在使用PHP而且我遇到了一个小问题。当我在没有变量的情况下运行脚本时,它会显示success=false,但是当我添加用户名并从数据库传递时,它会显示success=true

变量数量与第8行的预准备语句中的参数数量不匹配,然后从数据库中获取值。我的问题是,我做错了什么,问题出在哪里?

$con = mysqli_connect("mysql.hostinger.in", "test", "test", "test");

$name = $_POST["name"];
$password = $_POST["password"];

$statement = mysqli_prepare($con, "SELECT * FROM users WHERE name= ? AND password = ?");
mysqli_stmt_bind_param($statement, "ss", $name, $password);
mysqli_stmt_execute($statement);

mysqli_stmt_store_result($statement);
mysqli_stmt_bind_result($statement, $id, $name, $password, $email, $phonenumber);

$response = array();
$response["success"] = false;

while(mysqli_stmt_fetch($statement)){
    $response["success"] = true;  
    $response["name"] = $name;
    $response["password"] = $password;
    $response["email"] = $email;
    $response["phonenumber"] = $phonenumber;

}

echo json_encode($response);

0 个答案:

没有答案