我得到了下面的代码:如果检查选择查询语句被忽略
if(isset($_POST['vote'])){
if (!$wgUser->isLoggedIn()) {
// User is not online, don't accept the vote, set error message
$msg = 'Login required to vote.';
} if ($wgUser->isBlocked()) {
// User is banned, don't accept the vote, set error message
$msg = 'Account is banned.';
} else {
// User is online and not banned
$buildId = htmlspecialchars($_POST['id'], ENT_QUOTES, 'UTF-8');
$rating = htmlspecialchars($_POST['rating'], ENT_QUOTES, 'UTF-8');
$comment = htmlspecialchars($_POST['comment'], ENT_QUOTES, 'UTF-8');
$res = $db->select(
'build_rating',
array('article_id', 'username', 'vote', 'comment', 'date'),
array('article_id' => $buildId, 'username' => $wgUser->getName()),
__METHOD__
);
// Did user already vote on this build?
if (!$res) {
// Yes, let's update the vote and set success message
$db->update(
'build_rating',
array('vote' => $rating, 'comment' => $comment),
array('article_id' => $buildId, 'username' => $wgUser->getName()),
__METHOD__
);
$msg = 'Your vote has been successfully updated.';
} else {
// No, let's insert the vote and set success message
$db->insert(
'build_rating',
array('article_id' => $buildId, 'username' => $wgUser->getName(), 'vote' => $rating, 'comment' => $comment),
__METHOD__
);
$msg = 'Your vote has been successfully saved.';
}
}
}
是suposed保存用户评级的具体条款。除了检查用户是否已经投票的if语句(在这种情况下,它应该只是更新评分)或者它是全新的投票(在这种情况下,它应该将其保存为新的投票)之外,似乎一切正常工作。由于某些原因,因为每个投票都被保存为新投票,所以if语句不起作用。用户可以简单地放置100张选票,而实际上只能放置每篇文章一张。有人能指出我的错误吗?
在存入数据库时,不应该使用'htmlspecialchars'。它只能在网页上显示时使用。 – Barmar
这可能是问题吗?另外,你的意思是这样的:'$ output-> addHTML(htmlspecialchars($ outP),ENT_QUOTES,'UTF-8'));'? – Muki
我认为这与问题没有任何关系,只是一般性建议。 – Barmar