gpt4 book ai didi

php - 警告 : mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement in

转载 作者:行者123 更新时间:2023-11-29 21:19:20 25 4
gpt4 key购买 nike

我收到以下错误:

 Warning: mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement in  line 48

下面是第 48 行

mysqli_stmt_bind_result($stmt, $user_email, $user_pass);

下面是大部分代码

   // Using mysql_real_escape_string to ensure that the statements are legal SQL statements that can be stored
$email = mysqli_real_escape_string($con, $_POST['email']);
$password = mysqli_real_escape_string($con, $_POST['password']);


/*

Using Prepared statement to prevent SQL Injection

*/


// Create a perepared statement
if($stmt = mysqli_prepare($con, "SELECT * from admins WHERE user_email=? AND user_pass=?")) {


// Bind the paramaters
mysqli_stmt_bind_param($stmt, "ss", $email, $password);


// Execute the query
mysqli_stmt_execute($stmt);


/*

Usually we would bind the result to be able to retrieve their given value
However, in this case we are not interested in retrieving values from the database

*/
/* fetch value */
mysqli_stmt_fetch($stmt);


/* bind result variables */
mysqli_stmt_bind_result($stmt, $user_email, $user_pass);

echo $user_email;

连接已正确建立,即使没有在 myqsli_prepare 查询中设置条件,我仍然检索到相同的错误。

任何帮助将不胜感激。

最佳答案

问题是在 select 时您选择了 2 个以上的列,并且在 mysqli_stmt_bind_result 中只绑定(bind)了 2 个列,换句话说,select 中的列数必须与 mysqli_stmt_bind_result 中的变量数相同

要修复,请更改

SELECT * from admins WHERE user_email=? AND user_pass=?

致:

SELECT user_mail, user_pass from admins WHERE user_email=? AND user_pass=?"

关于php - 警告 : mysqli_stmt_bind_result(): Number of bind variables doesn't match number of fields in prepared statement in,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35775251/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com