jakeoh Posted October 10, 2007 Share Posted October 10, 2007 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 https://forums.phpfreaks.com/topic/72553-returning-the-results-of-two-mysql-inserts/ Share on other sites More sharing options...
coder_ Posted October 10, 2007 Share Posted October 10, 2007 Put results in array. $result['first'] = mysql_query($sql1); $result['second'] = mysql_query($sql2); return $result; Is this what you wont??? Link to comment https://forums.phpfreaks.com/topic/72553-returning-the-results-of-two-mysql-inserts/#findComment-365855 Share on other sites More sharing options...
MadTechie Posted October 10, 2007 Share Posted October 10, 2007 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 https://forums.phpfreaks.com/topic/72553-returning-the-results-of-two-mysql-inserts/#findComment-365857 Share on other sites More sharing options...
coder_ Posted October 10, 2007 Share Posted October 10, 2007 or that... Link to comment https://forums.phpfreaks.com/topic/72553-returning-the-results-of-two-mysql-inserts/#findComment-365858 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.