mySQL help needed - Stopping multiple competition entries

Associate
Joined
21 Mar 2007
Posts
41
Hi,

I'm trying to work out how to stop a user from entering a prize draw more than once. I've got this far:

<?
$user_id = $_COOKIE[user_id_login];
$userquery = mysql_query("SELECT * FROM prize_checkuser WHERE user='$user_id'");
$select_already = mysql_num_rows($userquery);

if($select_already){

echo("Your entry has been received, Thank You!</p>");

}else{

if($_POST['submit']){

//add user id to stop multiple voting
$user_id = $_COOKIE[user_id_login];
$addid = mysql_query("INSERT INTO prize_checkuser (user)". "VALUES ('$user_id')");


$hasvoted = 1;
}

$uri = $_SERVER['REQUEST_URI'];

//display the form!


if($hasvoted==1){

echo("Your vote has been successfully submitted, thanks! <a href=\"prizevote.php\">Click here to return</a><br/>");

}else{
?>
 
I'm assuming from that that you have to log in before you can vote. If so, just do a "select count(*) from vote_table where user_id = $_SESSION['user_id']" type thing to see if that user has already voted.

if they don't have to log in, then store the fact that they've voted in a cookie so that if they try to return, you can load some html that says "you can only vote once" or something similar
 
Sorry, that's gone right over my head. I'm rather new to mySQL!

The user has to be logged in, that's taken care of by a validateuser script.
I've got a data base that should store each user's id number (prize_checkuser) but nothing seems to be being sent to it. From what I understand (I inherited a good part of this code) a variable is created from the user's id number, which is then stored in a mySQL database once the user has entered. If a user tries to enter again, the mySQL database is supposed to check the user's id number to see if it's already stored there and, if it is, use $select_already to stop them voting again.

If that's what you were trying to say, I apologise, but can you pretty much spell it out for me!
 
Last edited:
Back
Top Bottom