JonnySnip3r Posted July 9, 2010 Share Posted July 9, 2010 Hey guys i have been making a website and i have hit a road block and hope someone can please help. Ok i have been making a signup page eassy however i have incorporated a messaging system into my website i have 2 tables so far one named members and one named pmessage (where the personal messages are held) the way i associate these tables with one another is in my pmessage i have a column named member_id which matched the id in the members table (hope this seems ok only way i couldt think) now i have a problem here is my sql code when a member registers. $register = mysql_query("INSERT INTO members (id,username,password,firstname,lastname,location,aboutme,profilepicture,age,private) VALUES ('','$username','$password','','','','','','','')"); as you can see i insert username and password everything else is null they can full this out in the profile area (hope this seems ok) i am pretty new to php. anyways how would i go about inserting whatever auto incremented id from the members table into the non auto increment member_id in the pmessages table? hope i explained that ok. anyways if i was to do it separately here is the code for that. $register_pmessages = mysql_query("INSERT INTO pmessages (id,member_id,title,message) VALUES ('','','','')"); really hope someone can help, and thanks!! Link to comment https://forums.phpfreaks.com/topic/207258-insert-into-multiple-tables-please-help-php/ Share on other sites More sharing options...
fenway Posted July 9, 2010 Share Posted July 9, 2010 You need to use last_insert_id() to get the newly created member's uid, then simply pass it through. Link to comment https://forums.phpfreaks.com/topic/207258-insert-into-multiple-tables-please-help-php/#findComment-1083740 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.