AdRock Posted August 24, 2007 Share Posted August 24, 2007 I have 2 tables in my MySQL database. 1 table to hold uer info and the other for newsletter signup. When a user registers i give them the option to sign up to newsletter but how do i insert the email address into the 2 tables in 1 sql statement? This is the main insert when a user registers $sql = mysql_query("INSERT INTO users (first_name, last_name, email_address, username, password, sex, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$sex', now())"); here is the sql or the newsletter signup mysql_query("INSERT INTO mailinglist SET email='" . $address . "'"); Is there a way I can insert the email address into both tables in 1 query Link to comment https://forums.phpfreaks.com/topic/66579-how-to-insert-into-2-tables-with-1-query/ Share on other sites More sharing options...
micmania1 Posted August 24, 2007 Share Posted August 24, 2007 $sql = "INSERT INTO users (first_name, last_name, email_address, username, password, sex, signup_date) VALUES('$first_name', '$last_name', '$email_address', '$username', '$db_password', '$sex', now());"; $sql .= " INSERT INTO mailinglist SET email='" . $address . "'");" $result = mysql_query($sql); I think that will work. I don't usually use 2 queries at once. I've just noticed your second query is wrong. $sql .= " INSERT INTO mailinglist (email) VALUES ('$address');"; Link to comment https://forums.phpfreaks.com/topic/66579-how-to-insert-into-2-tables-with-1-query/#findComment-333526 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.