为什么我试图通过ip地址检查双重投票,却不能正常工作?
if ($qtype === "sc"){
// single choice has only one select item
// check whether user has already answered this question
$i=0;
$res = mysqli_query($mysqli, "SELECT ip FROM votedanswers WHERE ip = \"".$ip."\" and qID = \"".$qID."\"");
while($obj = mysqli_fetch_object($res))
{
$i = $i+1;
}
if ($i > 0){
echo "your vote has already been counted";
}
else{
//insert data
$res = mysqli_query($mysqli, "INSERT INTO votedanswers (ip, qID, qQuestion, aID) VALUES ('$ip', '$qID', '$quest', '$aID')");
echo "your vote has been counted";
}
} else {
echo "nope!";
}`
不久前测试过,一切正常。但现在我想投多少就投多少。
1条答案
按热度按时间uqdfh47h1#
试试这个:
另请参阅:如何防止php中的sql注入?