我得到了下面的代碼:如果檢查選擇查詢語句被忽略
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