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.

Link to comment
Share on other sites

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);
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.