Jump to content

[SOLVED] Mysql inserting data two times :(


Recommended Posts

php is inserting the same row twice into mysql. I don't know why, and its starting to make me mad because the rest of my site doesn't do this. I've remade the database table twice, and stripped my code down.


Here is my code:



$add_product = $_GET['prod_id'];
$add_qty = $_GET['qty'];
$add_ip = $_SERVER['REMOTE_ADDR'];

mysql_connect("localhost", "root", "HIDDEN PASSWORD") or die(mysql_error());
mysql_select_db("db") or die(mysql_error());
mysql_query("INSERT INTO app_cart 
(prod_id, uid, qty, ip_addr) VALUES('$add_product', '0', '$add_qty', '$add_ip' ) ") 
or die(mysql_error());  


My DB is as follows:

id --> INT --> PRI KEY --> Auto Increment

prod_id --> INT

uid --> INT NULL

qty --> INT

ip_addr --> varchar 1000




Any insight? I'm clueless.

Link to post
Share on other sites

All in all, the core code itself doesnt seem at fault. It's like a problem in how the script is invoked. There are any number of things to look for unfortunately, from javascript refresh/redirects, to header redirects, to the user clicking the link more than once.


Do you have a debugger? Or use an IDE with one? It could easily tell you where the problem starts.

Link to post
Share on other sites


This topic is now archived and is closed to further replies.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.