0

Using a simple form I am posting into database. However its only posting into the first table ($sql) and not the second ($sql2). But I can not work out why. All the names match the values ect...

Am I missing something stupid. Any assistance would be great. Here is the part where its inserting $sql but not $sql2

I appreciate that the question of inserting data into to tables has been asked. However its not worked for me and want to check if I am missing something silly or going about this the wrong way.

$sql = "INSERT INTO accounts ( reg, acc, accstatus, carrfloor, carramid) 
VALUES ( '{$db->real_escape_string($_POST['reg'])}', 
         '{$db->real_escape_string($_POST['acc'])}', 
         '{$db->real_escape_string($_POST['accstatus'])}', 
         '{$db->real_escape_string($_POST['floor'])}',   
         '{$db->real_escape_string($_POST['carramid'])}' )"; 
   
$sql2 = "INSERT INTO platform ( platform, name, platformstatus, platformtype) 
VALUES ( '{$db->real_escape_string($_POST['platform'])}', 
         '{$db->real_escape_string($_POST['name'])}',
         '{$db->real_escape_string($_POST['platformstatus'])}',    
         '{$db->real_escape_string($_POST['platformtype'])}' )";
   
$insert = $db->query($sql); 
$insert2 = $db->query($sql2); 


if ($insert && $insert2) { 
echo "<font color='red'>Inserted Successfully</font>"; 
//header('Location: index');
} else { 
echo "<font color='red'>Woops! Something Went Wrong :|</font>"; 
} 


$db->close(); 
} 
 ?> 
scarlet
  • 15
  • 1
  • 5
  • Also marking this as a duplicated and stating its answered under a complely different question I don't understand "How to get mysqli error in different environments?(link:http://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-in-different-environments) " – scarlet Mar 30 '16 at 14:08
  • Just do what is said in the linked answer. – Your Common Sense Mar 30 '16 at 14:09
  • Hi I looked and the link and allowed it to show errors on screen. Except it was not seeing any error. However I know there is a problem as A: When it goes through the if statement and check if both $insert && $insert2 was inserted it throughs out the false condition of "Woops! Something Went Wrong". But inserting into the first table but not the secound. – scarlet Mar 30 '16 at 14:21
  • Can't be. There is either a succesful insert or an error. NO exceptions. – Your Common Sense Mar 30 '16 at 14:33
  • That's the point though. Its not giving me a mysqli error only the error of my if statement. Also to check that it was to echo an error on screen since I added error_reporting(E_ALL); and ini_set('display_errors',1); i purposely entered something wrong and it then displayed an error as expected. Sorry of i'm being stupid. – scarlet Mar 30 '16 at 14:44
  • So theirs nothing I can do? Its basically inserting first $sql into database, ignoring the $sql2. When it gets to the If Condition to see if both $sql and $sql2 where inserted echo's out error as required and confirm Woops something when wrong. Which is correct as only $sql was inserted into database, I have done error_reporting and nothing is displayed. this is now where I'm at and stumped :( – scarlet Mar 30 '16 at 15:13
  • did you add the mysqli_error() command? – Your Common Sense Mar 30 '16 at 15:26
  • yes and checked it was working be purposely making a mistake in the query which then gave me an error. – scarlet Mar 30 '16 at 15:27

0 Answers0