sql错误文本给了我一个与实际值不同的值

k10s72fa  于 2021-06-23  发布在  Mysql
关注(0)|答案(2)|浏览(337)

这是导致错误的代码行:

$result = $mysqli->query("SELECT * FROM 'accounts'.'users' WHERE email='$email' AND hash='$hash' AND active='0'") or die($mysqli->error);

这个错误表明:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ''accounts'.'users' WHERE email='testemail@email.com' AND hash='76dc611d6eba' at line 1

但是,如果我打印hash的值,我会得到这个“76dc611d6ebaafc66cc0879c71b5db5c”,即我要搜索的值和存储在数据库中的值。我不确定它是否只是被缩短为错误消息,如果其他事情正在发生。

njthzxwz

njthzxwz1#

尝试删除数据库和表名周围的引号

$mysqli = new mysqli("localhost", "my_user", "my_password", "world");

if ($mysqli->connect_errno) {
 printf("Connect failed: %s\n", $mysqli->connect_error);
 exit();
}

$result = $mysqli->query("SELECT * FROM accounts.users WHERE email='$email' AND hash='$hash' AND active='0'") or die($mysqli->error);
mtb9vblg

mtb9vblg2#

请尝试从'(撇号)改为'(反勾号),或者简单地从db/表名中删除单引号,这样您的查询如下所示:

SELECT * FROM `accounts`.`users` WHERE email='$email' AND hash='$hash' AND active='0'

相关问题