|
|
|||||||||
|
|||||||||
|
|||||||||
| |
|||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
||||
|
||||
|
how do I INSERT data into multiple tables at once?
You guessed it a newbie here!
I am building a site with members who have to create a member profile through PHP forms. I'd like to know the format to INSERT data into two linked tables (i.e. a 'users' table and a 'profile01'). Following is an example of what I am doing - the commented out part is data for the linked table: $strQuery = "INSERT INTO users ("; $strQuery .= "`username`, `password`, `usr_email`) VALUES ("; $strQuery .= "'{$_POST['strUserName']}', '$password', '{$_POST['strEmail']}')"; // $strQuery = "INSERT INTO profile01 ("; // $strQuery .= "`usr_sex`, `usr_dob`, `usr_zip`, `usr_country`, `usr_seeks`, `pom_ID`) VALUES ("; // $strQuery .= "'{$_POST['strDob']}', '{$_POST['strZip']}', '{$_POST['strCountry']}', '{$_POST['strSeeks']}', '{$_POST['strPom']}')"; if(mysql_query($strQuery)) { The 'users' table's Primary Key is an auto_increment 'usrID' field which is the foreign key for the 'profile_01' table. PLEASE HELP! |
|
#2
|
|||
|
|||
|
You just need to insert into one table, and then insert into the other.
After you've inserted the new user record, retrieve its usrID, and then insert that (+ all the other info) into the profile table. Hadley |
|
#3
|
||||
|
||||
|
thanks for the jumpstart!
Thanks for the jumpstart!
|
|
#4
|
|||
|
|||
|
I hear that MySQL 4.0 allows INSERT into multiple tables. Check the updated docs.
|
|
#5
|
|||
|
|||
|
Yes,
MySQL 4 supports inner/nested queries... So you can achieve that using this approach...
__________________
____________________________________________ Developer Shed Weekly Writer | DevArticles Forum Moderator Build Your Own KlipFolio Klip With PHP FrankManno.com - Under Construction Design Interactive Group - Under Construction |
![]() |
| Viewing: Dev Articles Community Forums > Databases > General SQL Development > how do I INSERT data into multiple tables at once? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|