Re:How to insert and update in two different tabl (1 viewing) (1) Guests
How to insert and update in two different tables
by jahflasher 1 Year, 1 Month ago
I have two tables. One that should be inserted into with new data and one that should be updated _base_d on the insertion from the other table. Both tables have a relation ship. How do i do the insertion then get the id of the inserted data to update another table. If only i new how to get the id of the inserted data then i would be able to do the update on the other table. Is this the best way to do this?
Last Edit: 10/06/2007 07:58pm By jahflasher.
The administrator has disabled public write access. | Report to moderator   Logged Logged  
Re:How to insert and update in two different tabl
by cyberpunk 1 Year, 1 Month ago
all you need to know is

Code: :

 mysql_insert_id();



this function will return the last id inserted into a table.

therefore

Code: :

  $query "insert into tablename(fieldname) values('$variable')"; mysql_query($query); $previd mysql_insert_id(); //now you have the new auto generated //primary id created your mysqlbackend. //you may now use that id to insert into //your other table to keep your relation in tact

Last Edit: 10/06/2007 09:22pm By cyberpunk.
The administrator has disabled public write access. | Report to moderator   Logged Logged  
Re:How to insert and update in two different tabl
by jahflasher 1 Year, 1 Month ago
Thanks a million for your help. You just saved my world from crashing in.
The administrator has disabled public write access. | Report to moderator   Logged Logged  
Re:How to insert and update in two different tabl
by cyberpunk 1 Year, 1 Month ago
Your welcome. Glad to help.
The administrator has disabled public write access. | Report to moderator   Logged Logged  
 
     
Powered by FireBoardget the latest posts directly to your desktop