这是导致错误的代码行:
$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
但是,如果我打印哈希值,则会得到“ 76dc611d6ebaafc66cc0879c71b5db5c”这个要搜索的值以及存储在数据库中的值。我不确定是否只是因为出现其他情况而将其缩短为错误消息。
答案 0 :(得分:2)
尝试从'(撇号)更改为`(反引号),或者只是从数据库/表名称中删除单引号,因此查询如下所示:
SELECT * FROM `accounts`.`users` WHERE email='$email' AND hash='$hash' AND active='0'
答案 1 :(得分:0)
尝试删除数据库和表名周围的引号
$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);