Jump to content

MySQL Inserting Two Rows


btoles

Recommended Posts

	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)

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.