Jump to content

entering data into two tables? HELP


hammersm

Recommended Posts

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
Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.