Jump to content

Returning the results of two MySQL Inserts


jakeoh

Recommended Posts

Hi,

 

How can I return the result of two MySQL inserts? When a new user register on the website, his info is inserted into a table, and his custom picture is inserted into a different table.

 

What I got so far is this:

 

	  <?php

$dbQuery = "INSERT INTO ".TBL_USER_AVATARS." VALUES (0, '$fileContent', 'image/png')";
  	  mysql_query($dbQuery, $this->connection) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $q . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
  $avatarNumber = mysql_insert_id();
  $q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel, '$email', '$firstname', '$lastname', '$address', '$city', $time, '$birthday', '$avatarNumber')";
  return mysql_query($q, $this->connection) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $q . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());

?>

 

This will return TRUE, but even if the first insert (the avatar) didn't work out. I want both inserts to be verified, and if the both succeed, then return TRUE.

 

Thanks.

or this ?

 

  <?php

$dbQuery = "INSERT INTO ".TBL_USER_AVATARS." VALUES (0, '$fileContent', 'image/png')";
  	  $A= mysql_query($dbQuery, $this->connection) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $q . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
$avatarNumber = mysql_insert_id();
  $q = "INSERT INTO ".TBL_USERS." VALUES ('$username', '$password', '0', $ulevel, '$email', '$firstname', '$lastname', '$address', '$city', $time, '$birthday', '$avatarNumber')";
  $B = mysql_query($q, $this->connection) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $q . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
return ($A && $B);
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.