Page 1 of 1

Mysql insert to two table

Posted: Thu Feb 03, 2011 8:42 am
by Linx
Hello. How to edit my script to insert data to two different table?
Here's my query:

Code: Select all

$query = mysql_query("SELECT * FROM users WHERE username = '$text'") or die(mysql_error());
if(mysql_num_rows($query)) {
echo "That user already exist!";exit;
}
mysql_query("INSERT INTO users (username, password, points) VALUES	('$text','$pass','$points')
");

Re: Mysql insert to two table

Posted: Thu Feb 03, 2011 9:20 am
by MindOverBody
You cant insert data into two table within one query. You must make two separate queries to do it.

Code: Select all

mysql_query("INSERT INTO table1 (column) VALUES (data)");
mysql_query("INSERT INTO table2 (column) VALUES (data)");