所以我正在尝试编写一个PHP脚本,记录每个用户一个投票增量。向选民a提供一份预期候选人名单,然后点击他们的名字一次。 现在尝试第二次,我希望得到一个允许这个动作的通知。请帮忙。
<?php
if(isset($_POST['vote']))
{
$sql3='INSERT INTO sessions (memberID, postid, email, voted) VALUES ("","", "", 1;)';
$result3 = mysqli_query($con, $sql3);
}
// $count = mysqli_num_rows($result2);
$candidate_name = null;
$vote = $_POST['vote'];
mysqli_query($con, "UPDATE tbCandidates SET candidate_votes=candidate_votes+1 WHERE position_id='$vote'");
// $count = mysqli_num_rows($result2);
if ( $count<1) {
//$sql3='INSERT INTO sessions (memberID, postid, voted) VALUES ("", memberbers.memberID,"1")';
//$result = mysqlI_query("select id from Users where username ='".$_SESSION['email']."'");
//$result = mysqli_query($con, $sql3);
// $count = mysqli_num_rows($result2);
} else {
echo"You have voted already";
}
答案 0 :(得分:0)
在SQL表的memberID列中放置一个“唯一”标志。在这种情况下,当您尝试插入具有相同memberID的新行时,它将无法工作。
然后捕获SQL写入失败,并在它到达时显示一条消息。