I am trying to insert the same data into the second table based on the first table created UserID
(auto-increment).
I created an INSERT query which inserts the user registration data into the users_tb
table. It works successfully. Then I need to insert the address describing data into the address_tb
table, based on the UserID
in users_tb
. But unfortunately it doesn't work.
//Rady to insert:
$results = $Street. ", " .$Apt. ", " .$City. ", " .$State. ", " .$ZipCode. ", " .$Country;
$query = mysql_query("INSERT INTO users_tb (UserId , FirstName , LastName , Email , Username , Password , Street , Apt , City , State , ZipCode , Country , Address , HomePhone , MobilePhone , Lat, Lng, Membership) VALUES ('' , '$First_Name' , '$Last_Name' , '$Email' , '$Username' , '$hashedPW' , '$Street' , '$Apt' , '$City' , '$State' ,'$ZipCode' ,'$Country' , '$results' , '$Ph_Number' , '$Mb_Number' , '0' , '0' , '1')");
// Insert Data into address_tb
$ad = mysql_query("SELECT UserID , Username FROM users_tb WHERE Username = $Username");
$adad = mysql_fetch_row($ad);
$UserID = mysql_real_escape_string($adad['UserID']);
$query = mysql_query("INSERT INTO address_tb (AddressID , Street , Apt , City , State , ZipCode , Country , Address , Lat , Lng , UserID) VALUES ('' , '$Street' , '$Apt' , '$City' , '$State' ,'$ZipCode' ,'$Country' , '$results' , '0' , '0' , '$UserID')");
I need to have the address fields also in my address_tb
table with the respective UserID
.