Jump to content


Photo

entering data into two tables? HELP


  • Please log in to reply
2 replies to this topic

#1 hammersm

hammersm
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 20 March 2006 - 05:47 PM

I have two tables, one with the colums
UserID , Email (UserID is autoincrementing(
the other with
UserID , Phone

I have a form that posts the email address and the phone to my handling page. So how do I write a query that enters the email address in the first table then gets the autoincremented UserID. Then enters the Phone in the other table with the same UserID that has just been created by the first INSERT query.

I have been trying to do this for ages with no luck.

If anyone can help I would be very happy,

Cheers

Mark

#2 trq

trq
  • Staff Alumni
  • Advanced Member
  • 31,041 posts

Posted 20 March 2006 - 05:52 PM

[!--quoteo--][div class=\'quotetop\']QUOTE[/div][div class=\'quotemain\'][!--quotec--]I have been trying to do this for ages with no luck.
[/quote]
Post your code.

#3 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 20 March 2006 - 05:54 PM

You cannot do that all in one query.

INSERT INTO table1 (col1, col2) VALUES (val1, val2)
run query
$new_id = mysql_insert_id($result);

INSERT INTO table2 (col1, col2) VALUES ($new_id, val2)
run query


Info: PHP Manual





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users