如何限制用户两次投票 [英] How can I restrict user from voting twice

查看:77
本文介绍了如何限制用户两次投票的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是php编码的新手,我正在尝试为我的学校开发一个在线投票系统作为我的最终项目。已完成所有编码和设计,一切正常,但当注册用户注销和登录时,用户可以多次投票并继续阅读。我想知道如何限制用户两次投票,所以第二次让用户登录,它应该将用户重定向到另一个页面



我尝试了什么:



I'm new on php coding and I'm trying to develop an online voting system for my school as my final project. Have done all the coding and designing , everything is working fine, but when the registered user logout and login, the user can be able to vote more than once and it keeps reading. Please I want to know how to restrict user from voting twice, so incase the user login in the second time, it should redirect the user to another page

What I have tried:

<?php

$con = mysqli_connect("localhost", "root", "password007", "university portal");

if(isset($_POST['radio'])){
	mysqli_query($con, "update candidate set Vote=Vote+1 where UserID=$_POST[radio]");
	
	$insertGoTo = "Voting2.php";
  header(sprintf("Location: %s", $insertGoTo));
	
}

?>
<!doctype html>




<meta charset="utf-8">
<title>Voting




	function preventBack(){window.history.forward();}
	setTimeout("preventBack()", 0);
	window.onunload = function() {null};
	



<div id="Holder">
	<div id="Header">
		<a href="Home.php"></a>
	</div>
	<div id="NavBar">
		
    	<ul>
        	<li><a href="Home.php">Home</a></li>
            <li><a href="Login.php">Student Portal</a>
            <ul>
            	<li><a href="Login.php">Login</a></li>
            	<li><a href="Candidate%20Profile.php">Candidates Profile</a></li>
            </ul>
			</li>
            <li><a href="Admin.php">Admin</a></li>
            <li><a href="About%20Site.php">About Us</a>
            <ul>
            	<li><a href="About%20Site.php">About Site</a></li>
            	<li><a href="Contact%20Us.php">Contact Us</a></li>
            </ul>
            </li>
        </ul>
    
	</div>
	<div id="Content">
		<div id="PageHeading">
	  <h1> </h1>
	  <h1> </h1>
	  <h1>President</h1>
      </div>
	<div id="ContentLeft">
	  <h2>Your Message Here</h2>
	  <h6>Note: vote wisely, once you've voted you cannot go back.</h6>
	</div>
	<div id="ContentRight">
	  
	    
	      
	        
	          
            
	        
	          
            
	        
	          
            
	        
	          
            
	        
	          
            
	        
	          
            
	        
	          
            
	        
	          
            
          
        <table width="400" border="0" align="center"><tbody><tr><td>
	            
	              
	                
	                
	              
              <table border="0" align="center"><tbody><tr><td><h6>For President</h6></td></tr></tbody></table></td></tr><tr><td> </td></tr><tr><td>
	            
	              
	                
	                
	                
	              
              <table width="397" border="0"><tbody><tr><td width="102"></td><td width="282"><h6>
	                      
	                  OBINNA DANIEL CHUKWUKA</h6></td></tr></tbody></table></td></tr><tr><td> </td></tr><tr><td>
	            
	              
	                
	                
	                
	              
              <table width="397" border="0"><tbody><tr><td width="101"></td><td width="286"><h6>
                     
                      ABUBAKA KAYODE </h6></td></tr></tbody></table></td></tr><tr><td> </td></tr><tr><td>
	            
	              
	                
	                
	              
              <table border="0" align="center"><tbody><tr><td></td></tr></tbody></table></td></tr><tr><td> </td></tr></tbody></table>
        
	  
	</div>
	</div>
	<div id="Footer"></div>
</div>
<p> </p>


<?php
mysql_free_result($voting);
?>

推荐答案

con = mysqli_connect( localhost root password007,< span class =code-string> university portal);

if(isset(
con = mysqli_connect("localhost", "root", "password007", "university portal"); if(isset(


_POST [' radio'])){
mysqli_query(
_POST['radio'])){ mysqli_query(


con, 更新候选集投票=投票+ 1,其中UserID =
con, "update candidate set Vote=Vote+1 where UserID=


这篇关于如何限制用户两次投票的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆