miket3 Posted August 19, 2009 Share Posted August 19, 2009 I have a table with field [REC_ID] as PRIMARY KEY and AUTO INCREMENT. These next few lines of code cause an extra record to be INSERTED into my table. When I say extra I mean 2 records instead of 1. The freaky thing is that my PRINTF's report the correct numbers. However when I check the table I got an extra record. If I comment out the SELECT statement I only get the 1 record inserted as expected. I have tried this with INSERT INTO, with and without DUPLICATE KEY. It even gets better... The line where I increment the $couponid actually comes thru in both of the inserted records. It is as if the code is being executed twice. Yet my PRINTF's dont print twice. And this only works improperly when the INSERT and the SELECT are live statements. $couponid=USERNAME."-".strval($count+1); $result = mysql_query("INSERT ".COUPONTABLE." (memberid,couponid,couponconfig) VALUES('".$memberid."','".$couponid."','".$couponconfig."') ON DUPLICATE KEY UPDATE couponid='".$couponid."'"); printf("Records inserted: %d\n", mysql_affected_rows()); // $rec_id = mysql_insert_id(); } $sql="SELECT * FROM ".COUPONTABLE." WHERE memberid = '".$memberid."'"; $result = mysql_query($sql); printf("Records selected: %d\n", mysql_affected_rows()); Any takers on this freaky thing? Link to comment https://forums.phpfreaks.com/topic/171013-solved-stumped-on-mysql-insert/ Share on other sites More sharing options...
miket3 Posted August 19, 2009 Author Share Posted August 19, 2009 ok. I am getting closer. The page is actually being executed twice. I added a sleep() statement and for some reason she is running twice. The script is being called from another script via an <a href> link. I added these lines after my queries.... echo "Sleeping..."; sleep(20); echo "done sleeping"; When I click on the link from my calling script, nothing echoes to the screen on the first round. it is being buffered i thru in an ob_flush() at top of the script but it didnt help. In case you are wondering... There are no loops in my code. Just a big loop trying to write this code... Link to comment https://forums.phpfreaks.com/topic/171013-solved-stumped-on-mysql-insert/#findComment-901971 Share on other sites More sharing options...
miket3 Posted August 19, 2009 Author Share Posted August 19, 2009 I just ran my code on IE and it worked fine. Something is causing Firefox to send 2 server requests when I click on a link. Wow is that not good... Link to comment https://forums.phpfreaks.com/topic/171013-solved-stumped-on-mysql-insert/#findComment-902003 Share on other sites More sharing options...
miket3 Posted August 19, 2009 Author Share Posted August 19, 2009 ok. here is the BUG <img src=""></img> Firefox is known to fire multiple server requests when you leave TAG attributes empty. Of course, the guys who respond to the firefox/mozilla bug reports wont really admit that it is a bug. But they know about the issue. In my book, it is a BUG. Ok you might be wondering why you would have an empty attribute. Well.... There is a wonderful thing called Javascript frameworks, and it is very common to change TAG attributes on the fly, and starting out empty isnt all that uncommon anymore. Link to comment https://forums.phpfreaks.com/topic/171013-solved-stumped-on-mysql-insert/#findComment-902037 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.