Update and Insert simultaneously

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
wartsolio
Forum Newbie
Posts: 2
Joined: Mon Feb 16, 2009 1:34 pm

Update and Insert simultaneously

Post by wartsolio »

Is there a way to update and insert at the same time?

What I'm trying to do is allow users to edit some information, and a part of the editing might be to add additional information.

I'm using an if(isset) to check the _POST if there is any information there. The problem is that if I add something to the info, it takes the last set of data and overwrites the original piece of data.

If anyone has any ideas, I'd greatly appreciate it.

Thanks,

w.
josh
DevNet Master
Posts: 4872
Joined: Wed Feb 11, 2004 3:23 pm
Location: Palm beach, Florida

Re: Update and Insert simultaneously

Post by josh »

You can either put all the fields on one table and issue 1 update statement, or create multiple tables and issue the queries separately. There's trade offs to both approaches that will be obvious if you start experimenting around
wartsolio
Forum Newbie
Posts: 2
Joined: Mon Feb 16, 2009 1:34 pm

Re: Update and Insert simultaneously

Post by wartsolio »

Yeah, they're in separate tables; too much information to hold in a single table.

What I got to work was to do a select on the table to see if one of the fields came back as an array, and ran from there.

Thanks.
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

Re: Update and Insert simultaneously

Post by SpecialK »

have you looked into the INSERT... ON DUPLICATE KEY UPDATE?
http://dev.mysql.com/doc/refman/5.0/en/ ... icate.html
Post Reply