A question
- blah569
-
blah569
- Member since: Jan. 18, 2005
- Offline.
-
- Forum Stats
- Member
- Level 25
- Programmer
Ok, I only want the user to be able to only vote once... I log their IP into the datebase... it works... so the IP is $ip. Now... I only want someone to be able to vote once with their IP. How can I go about doing this? Please help. Thanks.
- harryjarry
-
harryjarry
- Member since: May. 15, 2005
- Offline.
-
- Forum Stats
- Member
- Level 57
- Blank Slate
Before you log the votes do something like
$ipquery = mysql_query("SELECT * FROM `votes` WHERE ip='$ip'");
$ipcheck = mysql_num_rows($ipquery);
if($ipcheck >= 1) {
die('You have already voted on this!');
}
Although you would need to chance 'votes' to whatever your table name is.
- henke37
-
henke37
- Member since: Sep. 10, 2004
- Offline.
-
- Forum Stats
- Member
- Level 30
- Blank Slate
Or make the ip the primary colum and check the error from the result, the error code will tel your script if the query failed because of a duplicate key or something else.
Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.
- blah569
-
blah569
- Member since: Jan. 18, 2005
- Offline.
-
- Forum Stats
- Member
- Level 25
- Programmer
It does not work. My Code:
<?php
$getflash = mysql_query("SELECT * from flashes where id = '$_GET[id]'");
$flashnum = mysql_num_rows($getflash);
if ($flashnum == 0)
{
echo ("Flash not found.");
}
else
{
$ipquery = mysql_query("SELECT * FROM `votelog` WHERE ip='$ip'");
$ipcheck = mysql_num_rows($ipquery);
if($ipcheck >= 1) {
die("You have already voted on this!");
}else{
$flash = mysql_fetch_array($getflash);
$ip = $_SERVER['REMOTE_ADDR'];
$update = mysql_query("UPDATE flashes SET avg = pros / cons / 2, pros = pros + 1 WHERE id='$flash[id]'");
mysql_query("INSERT * INTO votelog ('ip', 'vote') VALUES ('$ip', 'pro')");
}
?>
Please help.
- Loccie
-
Loccie
- Member since: Feb. 27, 2004
- Offline.
-
- Forum Stats
- Member
- Level 16
- Blank Slate
This is probably not right what I am says but could it be because the variable $ip is used here
$ipquery = mysql_query("SELECT * FROM `votelog` WHERE ip='$ip'");
but only set later. Or are you only giving a part of the script?



