Jump to content

INSERT and DELETE in the same step!?!


darylesha

Recommended Posts

I am new to php coding and website design. I was wondering if anyone could help me figure something out.

Okay so I have a dynamic website that prints the info in the database out with checkboxes next to it. When a user checks the boxes and press the submit button, the record should be deleted from the database and then they should be stored in another database that assigns a different primary key ( not in that order). Also I would like for the user to be redirected back to the same page and for the records that were deleted, not to show up.

I'm figuring that I need to use a if...else statement as well as some type of loop. Any other help would be greatly appreciated!

 

Link to comment
Share on other sites

if you are moving data from one database or table to another one.

 

I recommend a 3 step approach.

1: UPDATE any information you are changing, in the original database.

2: Use REPLACE INTO and copy the rows of data you need over to the new db / table.

3: once that succeeds then DELETE the rows from the original.

 

 

 

Link to comment
Share on other sites

in addition to what grimmier wrote:

 

instead of step 3 where you would delete all rows out of a table you will probably not use anymore, use:

 

DROP TABLE your_table

 

this will delete the complete table

 

Yeah i didn't want to put this in there, incase it was just moving certain rows.

 

I use the 3 step approach when moving inventory items from the main DB to the relief DB.

 

To add to ignace some. If you are moving everything and want to keep the old table . use Empty Table. it removes the data, leaves the structure and resets the auto incriments.

Link to comment
Share on other sites

if you are moving data from one database or table to another one.

 

I recommend a 3 step approach.

1: UPDATE any information you are changing, in the original database.

2: Use REPLACE INTO and copy the rows of data you need over to the new db / table.

3: once that succeeds then DELETE the rows from the original.

 

REPLACE INTO would be a bad idea as the questioner stated the PKs will be different in the other table

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.