Be a Supporter!

A question

  • 386 Views
  • 4 Replies
New Topic Respond to this Topic
blah569
blah569
  • Member since: Jan. 18, 2005
  • Offline.
Forum Stats
Member
Level 25
Programmer
A question 2006-12-04 22:15:02 Reply

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.


BBS Signature
harryjarry
harryjarry
  • Member since: May. 15, 2005
  • Offline.
Forum Stats
Member
Level 57
Blank Slate
Response to A question 2006-12-05 00:37:10 Reply

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.


twitter | last.fm // Currently working on HarryJarry.com

BBS Signature
henke37
henke37
  • Member since: Sep. 10, 2004
  • Offline.
Forum Stats
Member
Level 30
Blank Slate
Response to A question 2006-12-05 06:09:29 Reply

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
Response to A question 2006-12-05 17:42:49 Reply

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.


BBS Signature
Loccie
Loccie
  • Member since: Feb. 27, 2004
  • Offline.
Forum Stats
Member
Level 16
Blank Slate
Response to A question 2006-12-06 00:20:54 Reply

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?