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:

 

<?php

$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 comment
https://forums.phpfreaks.com/topic/128036-solved-mysql-inserting-data-two-times/
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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.