Beyond that excellent answer, this is exactly the kind of situation where
transactions would be helpful (and in a lot of cases, mission critical).

So an expanded quasi-pseudocode rendition of olinux's answer could be:

$result_bt = mysql_query('[whatever it takes to begin a transaction]');
$result_1 = mysql_query($sql1);
if (!$result_1) {
  $result_rb = mysql_query('[whatever it takes to rollback a transaction']);
  /* whatever else you want to do, such as show an error message */
}
else {
  $result_2 = mysql_query($sql2);
  if (!$result_2) {
    $result_rb = mysql_query('[whatever it takes to rollback a transaction']);
    /* whatever else you want to do, such as show an error message */
  }
  else {
    $result_et = mysql_query('[whatever it takes to commit a transaction']);
} }

If your implementation of MySQL supports transactions (and if it doesn't
then either change databases or web hosts), use them.  It helps ensure the
integrity of the data.  Please feel free to be more elegant in the error
checking...the above is just an example and would undoubtedly not be used,
even fixed up for syntax, on a production site.

Doug

At 10:25 PM 7/28/01 -0500, olinux wrote:
>Not possible.
>
>do this $result_1 = mysql_query($sql1) or die('Insert 1 failed');
>do this $result_2 = mysql_query($sql2) or die('Insert 2 failed');
>
>olinux
>
>-----Original Message-----
>From: Steve Fitzgerald [mailto:[EMAIL PROTECTED]]
>
>I'm trying to insert data into two separate tables using 1 INSERT.
  ... snip ...


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to