gpt4 book ai didi

php - Mysqli 准备语句 stmt_num_rows 返回 0

转载 作者:行者123 更新时间:2023-11-28 23:37:09 25 4
gpt4 key购买 nike

出于某种原因,stmt_num_rows 总是以 0 结束。无论我使用正确的电子邮件和单词执行查询还是错误的。这是代码:

    include_once './Connect.php';

$db = new DB_Connect();
$con = $db->connect();

$password = $_POST["Password"];
$email = $_POST["Email"];
$word = $_POST["Word"];
$true = 'true';
$false = 'false';
$response = array();


$selectquery = mysqli_prepare($con, "SELECT ID FROM users WHERE Email = ? AND Word = ?");
mysqli_stmt_bind_param($selectquery , "ss" , $email , $word);
mysqli_stmt_execute($selectquery);
mysqli_stmt_store_result($selectquery);
mysqli_stmt_bind_result($selectquery, $ID);


if (mysqli_stmt_num_rows($selectquery) > 0){
$response[resp] = $true;
$updatequery = mysqli_prepare($con , "UPDATE users SET Password = ? WHERE Email = ? AND Word = ?");
mysqli_stmt_bind_param($updatequery ,"sss", $password, $email, $word);
mysqli_stmt_execute($updatequery);
mysqli_stmt_close($updatequery);
}else{
$response[resp] = $false;
}


echo json_encode($response);
mysqli_stmt_close($selectquery);
mysqli_close($con);

代码运行:密码电子邮件Word是从android发布的。首先有一个查询来检查表中是否有一个用户(行)具有相应的 Email 和 Word。如果是,则添加 ID。然后调用 stmt_num_rows 来检查获取的行数,但获取的行数最终为 0(我得到的响应为“false”)。但如果它是一个,那么将调用 UPDATE 查询并且我将收到响应“true”。有谁知道我犯的错误?

谢谢!

最佳答案

将我们的评论放在答案中以结束此问题:

我的:

"Try removing / commenting those out and try it again. If that fails, then your POSTs may be failing. Check for errors against those and variables, and in your query."

和:

"also make sure that no whitespace is being introduced, if so, trim() and do a var_dump. Remember that POST arrays are case-sensitive. Password and password etc. are two different animals. Same goes for the other POST arrays"

伊万的:

"Fred you were right the issue wasn't in the php it was actually the data posted. Since I'm using the Async Http library i forgot to post the actual parameters I want to send. I set the params to null"


密码

我注意到您可能以明文形式存储密码。不建议这样做。

使用以下之一:

其他链接:

关于列长度的重要旁注:

如果您决定使用 password_hash() 或 crypt,请务必注意,如果您当前的密码列的长度低于 60,则需要将其更改为(或更高)。手册建议长度为 255。

您需要更改列的长度并使用新的散列重新开始才能生效。否则,MySQL 将无提示地失败。

关于php - Mysqli 准备语句 stmt_num_rows 返回 0,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35470705/

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