PDA

View Full Version : Insert into two tables at once


Cygnus
Mon 15th Oct '01, 11:32pm
Is it possible to insert information into two tables at the same time?

For example, I would like to write an insert script that looks like this:

INSERT into USER values
('$username', '$password', '$email', '$first_pick') AND
INSERT into SCORES values
('$username', '$score')

I know that that won't work but is there something that I can do that will basically do the same thing with the click of one submit button?

Thanks in advance!
Cygnus

Cygnus
Sun 21st Oct '01, 4:04pm
Answer:

$result = mysql_query("insert into user values
('$username', password('$password'), '$email', '$firstpick')");
if (!$result)
return "<p class='text'>Could not register you in database - please try again later.</p>";

$result = mysql_query("insert into scores values
('$username', '300.0', '', '')");
if (!$result)
return "<p class='text'>Could not register you in database - please try again later.</p>";

You can have multiple queries executed with the click of one button.

Cygnus