Mysql insert to two table

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
Linx
Forum Newbie
Posts: 3
Joined: Thu Feb 03, 2011 8:36 am

Mysql insert to two table

Post 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')
");
User avatar
MindOverBody
Forum Commoner
Posts: 96
Joined: Fri Aug 06, 2010 9:01 pm
Location: Osijek, Croatia

Re: Mysql insert to two table

Post 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)");
Post Reply