我有下面的代码是应该 1在一份PHP MySQL的语句来增加一个字段值:问题在MySQL/PHP递增场预处理语句
function db_OP_doVote($pdo, $postid, $votetype)
{
$prepStatement = $pdo->prepare(
"UPDATE content_posts SET `:votetype` = `:votetype` + 1 WHERE `id` = :id"
);
$prepStatement->execute(array(':votetype' => $votetype, ':id' => $postid));
echo "Success";
}
然而,这什么都不做。没有错误返回关于不正确的SQL语法,脚本运行完成,但我的字段根本不会更新。
此脚本的值是通过一个jQuery后()这个脚本反馈:
//isset checking here
$postID = (int)$_POST['id'];
$voteType = $_POST['type'];
if ($voteType == "y")
{
$trueType = "v-cool";
}
elseif ($voteType == "m")
{
$trueType = "v-meh";
}
elseif ($voteType == "n")
{
$trueType = "v-shit";
}
else
{
die();
}
$db = db_Connect();
db_OP_doVote($db, $postID, $trueType);
这似乎也在筛选值和精细送他们。我无法解决问题的可能性。增加的字段是BIGINT(20)。
我错过了什么?
编辑:解决了这个问题。 012BJ的评论点击头部 - 绑定列名会导致它被引用,这会使查询无效。谢谢!
votetype是int或字符? :S – JellyBelly
char。该问题似乎不是与ajax-> values脚本相关,而是与准备好的语句相同 - :votetype似乎没有准备好 – Ephemeralis
您不应该在预准备语句中绑定列名称。为什么?因为他们被引用。你的':votetype'实际上是''votetype''。这可能是报告错误,但我看不到你在哪里捕捉它。 –