General SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 
Go Back   Dev Articles Community ForumsDatabasesGeneral SQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old April 15th, 2003, 12:52 AM
Mojoman's Avatar
Mojoman Mojoman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Washington, DC
Posts: 39 Mojoman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 34 m 34 sec
Reputation Power: 6
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!

Reply With Quote
  #2  
Old April 15th, 2003, 05:57 AM
hadley hadley is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Aug 2002
Posts: 63 hadley User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
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

Reply With Quote
  #3  
Old April 15th, 2003, 06:04 PM
Mojoman's Avatar
Mojoman Mojoman is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Apr 2003
Location: Washington, DC
Posts: 39 Mojoman User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 34 m 34 sec
Reputation Power: 6
thanks for the jumpstart!

Thanks for the jumpstart!

Reply With Quote
  #4  
Old April 22nd, 2003, 02:42 AM
avit avit is offline
Not Yet Perfect
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Nov 2002
Location: Squamish, BC
Posts: 111 avit User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 7
Send a message via ICQ to avit
I hear that MySQL 4.0 allows INSERT into multiple tables. Check the updated docs.

Reply With Quote
  #5  
Old April 24th, 2003, 08:07 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
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

Reply With Quote
Reply

Viewing: Dev Articles Community ForumsDatabasesGeneral SQL Development > how do I INSERT data into multiple tables at once?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway
Stay green...Green IT