Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
<?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);
?>
Posted
Updated 26-Jan-17 0:51am
v2
Comments
PIEBALDconsult 24-Jan-17 18:37pm    
I would just handle it in reporting, report only the final vote by each user. I don't like systems that don't allow users to correct their votes.
Daniel Chuks 25-Jan-17 4:37am    
How do I report it, need a sample
Richard MacCutchan 25-Jan-17 5:10am    
You just need to read the user's vote record when they login. If they have already voted once then either allow a correction, or reject it with a message.

1 solution

You need to record that the user has voted along with their vote. I would do this in two separate tables; one for votes, one for a list of those who voted.

You can then check to see if they've voted and respond accordingly.

In the above comments, one responder notes that they prefer the ability to change votes. This has two sides:

Good - that the user can change their mind or undo mistakes
Bad - that the user's vote is no longer private/secret, since it is connected to their ID

Depending upon the kind of voting it is depends upon whether secrecy of the ballot is important.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900