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 'WHERE Username=''' at line 1
代码如下:
$sql="UPDATE users SET Password=$pass_word WHERE Username='$_POST[username]'";
最佳答案
这是非常危险的编码。如果有人(传统上称为 Little Bobby Tables )将其密码更改为
hello';--
你的查询变成了
UPDATE users SET Password='hello';-- ' WHERE Username='$_POST[username]'";
其中——作为一条评论,被解释为非常广泛
UPDATE users SET Password='hello';
您现在的错误是您忘记了密码周围的引号 - 但您应该做的是移至 PDO 。那么你的查询可能会变成
$stmt = $dbh->prepare('UPDATE users SET Password=? WHERE Username=?');
$stmt->execute($pass_word, $_POST['username']);
PDO 层负责避免麻烦。
同样的情况也适用于 $_POST[username]
,我建议你将其写为“{$_POST['username']}” - 它更容易被多个 PHP 工具解析,并且让您可以更灵活地处理复杂的数组。
关于php - SET Password=$password 后出现语法错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47464049/