how to insert values in mysql table using php

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
srichandar
Forum Newbie
Posts: 6
Joined: Thu Apr 02, 2009 9:36 am

how to insert values in mysql table using php

Post by srichandar »

Hi all,
I want to insert the values from php registration form in to mysql db using the foreign key,

Table structure,
Table1:
userid primary key autoincrement,
username
emailid

Table 2:
id
Phone number
Address
Fax
Foreign key(id) reference Table1(userid)

for inserting values into table2 i have to use the Table1's primarykey, Question is how to get the table1's primary key and insert into table2.

thanks in advance,
sridhar
User avatar
jayshields
DevNet Resident
Posts: 1912
Joined: Mon Aug 22, 2005 12:11 pm
Location: Leeds/Manchester, England

Re: how to insert values in mysql table using php

Post by jayshields »

Why have you split up those tables, and why is the relationship one-to-many going from user details to contact details? Are you going to assign multiple sets of contact details to each user?

However, the solution is to use mysql_insert_id().
Post Reply