btoles Posted July 22, 2009 Share Posted July 22, 2009 if($_GET['action'] == "move") { $id = $_GET['item_id']; $inv = mysql_fetch_object(mysql_query("SELECT * FROM `inventory` WHERE `item_id` = '$id' LIMIT 1")); mysql_query("INSERT INTO `storage` (`item_id`, `data_id`, `user_id`) VALUES ('$id', '$inv->data_id', '$thisuser->id')") or die(mysql_error()); mysql_query("DELETE FROM `inventory` WHERE `item_id` = '$id'") or die(mysql_error()); echo "<center>Your item has been moved to storage</center>"; } The line is the INSERT, it inserts two rows everytime I use the query, they are exactly identical except one has no data_id. I only want it to insert ONE ROW!!!! It's doing this to me with another table as well (inventory table) Quote Link to comment https://forums.phpfreaks.com/topic/166882-mysql-inserting-two-rows/ Share on other sites More sharing options...
PFMaBiSmAd Posted July 22, 2009 Share Posted July 22, 2009 Your code is being executed twice. This is usually because your browser requested the page twice but it can also be cause by url rewriting or if you are including code twice or doing a redirect that causes the code to be executed twice. The best way to prevent this (assuming it not being caused by a logic error in your code) is to put some validation logic in your code. If the SELECT query fails and does not return anything for $inv->data_id, don't execute the INSERT and DELETE queries. Quote Link to comment https://forums.phpfreaks.com/topic/166882-mysql-inserting-two-rows/#findComment-879941 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.