这里有什么问题
JS
function cstatus(status, user, pass){
var id = $('.pmarked').data('id');
console.log(id); // 101
$.ajax({
url: 'pro-status.php',
type: 'post',
data: {'status': status, 'user': user, 'pass': pass, 'id': id},
success: function(data) {
console.log(data);
}
});
}
亲status.php
$sql = "update posts set status = :astatus, user = :auser, pass = :apass, where id = :aid";
$stmt = $db->prepare($sql);
$stmt->execute(array(
":astatus" => $_POST['status'],
":auser" => $_POST['user'],
":apass" => $_POST['pass'],
":aid" => $_POST['id'] // line 12
));
错误
致命错误......在'where id ='101''附近使用正确的语法... ... pro-status.php:12
答案 0 :(得分:6)
删除逗号:
pass = :apass, where id = :aid"
应该是:
pass = :apass where id = :aid"
此外,永远不会存储纯文本密码!请使用 PHP built-in functions 来处理密码安全问题。如果您使用的PHP版本低于5.5,则可以使用password_hash()
compatibility pack。 没有必要escape passwords 或在散列之前对它们使用任何其他清理机制。这样做更改密码并导致不必要的额外编码。
答案 1 :(得分:3)
应该是
$sql = "update posts set status = :astatus, user = :auser, pass = :apass where id = :aid";
只需删除comma (,)
:apass
即可
答案 2 :(得分:2)
SQL语法问题请删除逗号并在$ sql上使用它。
$sql = "update posts set status = :astatus, user = :auser, pass = :apass where id = :aid";
答案 3 :(得分:2)
在,
where
$sql = "update posts set status = :astatus, user = :auser, pass = :apass where id = :aid";