STILL NEED HELP! If you only see four replies to this post!!
Posted: Wed Nov 13, 2002 3:28 pm
Very strange stuff here.
I created a few "polling" sites and am having a strange problem over each. I have an IP-checking logic that tests to see if user at IP has voted previous; if not, user's vote is logged.
Now the strange stuff. I am, at random, getting double entries simultaneously. <sp?> Every so often, a person's vote is logged exactly twice, and so is their IP, both double entries are in separate tables. The "auto-increment" id's are incremented properly and the datetime col, instantiated with NOW(), has the same datetime right down to the second. I have tried to repeat this on my own, (ie. double clicking, returning to vote after i have voted then changed my IP) I can not seem to cause the error to happen consistantly, I can, however, cause the double entry every so often, seemingly at randomly.
Now, I know that using:
$sql = "insert or update stmt...";
$result = mysql_query($sql);
if($result)...
can cause duplicate entries when you do the "if" statement, seemingly becuase $result is being reinstantiated on first-use.
My code:
$sql = "INSERT INTO poll VALUES('',".$opt_1.",".$opt_2.",NOW())";
mysql_query($sql) or die('poll insert error: '.mysql_error());
mysql_free_result();
$sql_ip = "INSERT INTO ip_addys VALUES('','".$ip."',NOW())";
mysql_query($sql_ip) or die('ip insert error: '.mysql_error());
mysql_free_result();
The id column is the first col; it is left to mySQL to determine its value.
I know a "good" fix would be to SELECT the MAX(id)+1 and use that in my INSERT to utilize the primary-keys UNIQUE feature. But this would cause me to change alot of code on a highly used site. I am looking for a "real" fix, as these voting sites are being hit hundreds of times a day.
Help, anyone?

I created a few "polling" sites and am having a strange problem over each. I have an IP-checking logic that tests to see if user at IP has voted previous; if not, user's vote is logged.
Now the strange stuff. I am, at random, getting double entries simultaneously. <sp?> Every so often, a person's vote is logged exactly twice, and so is their IP, both double entries are in separate tables. The "auto-increment" id's are incremented properly and the datetime col, instantiated with NOW(), has the same datetime right down to the second. I have tried to repeat this on my own, (ie. double clicking, returning to vote after i have voted then changed my IP) I can not seem to cause the error to happen consistantly, I can, however, cause the double entry every so often, seemingly at randomly.
Now, I know that using:
$sql = "insert or update stmt...";
$result = mysql_query($sql);
if($result)...
can cause duplicate entries when you do the "if" statement, seemingly becuase $result is being reinstantiated on first-use.
My code:
$sql = "INSERT INTO poll VALUES('',".$opt_1.",".$opt_2.",NOW())";
mysql_query($sql) or die('poll insert error: '.mysql_error());
mysql_free_result();
$sql_ip = "INSERT INTO ip_addys VALUES('','".$ip."',NOW())";
mysql_query($sql_ip) or die('ip insert error: '.mysql_error());
mysql_free_result();
The id column is the first col; it is left to mySQL to determine its value.
I know a "good" fix would be to SELECT the MAX(id)+1 and use that in my INSERT to utilize the primary-keys UNIQUE feature. But this would cause me to change alot of code on a highly used site. I am looking for a "real" fix, as these voting sites are being hit hundreds of times a day.