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 Quote Link to comment 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');"; Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.