0

I'm looking to enter in a whole object of information. The data itself needs to be put into different tables so I'm using a mysqli_multi_query

Query

for($i=0;$i<$commLength;$i++){
  $sql = "INSERT INTO
  calinfo (Sbefore, Safter, A1, A2, CalGas, Factor, Zbefore, Zafter, Cbefore, Cafter, SysInfoID)
  VALUES
  ('{$comm[$i]->ScB4}', '{$comm[$i]->ScA4}', '{$comm[$i]->A1}', '{$comm[$i]->A2}', '{$comm[$i]->CalGasA}', '{$comm[$i]->Factor}', '{$comm[$i]->ZB4}', '{$comm[$i]->ZA4}', '{$comm[$i]->CalB4}', '{$comm[$i]->CalA4}', '{$comm[$i]->CHNoID}');";

  $sql .= "UPDATE
  jobs
  SET
  CompletedBy = $tech
  WHERE JobID = '{$comm[$i]->JobID}';";
  if(!mysqli_multi_query($con,$sql))
  {
     die('Error: ' . mysqli_error($con));
  }
  else
  {
     $synctotal++;
  }
}

I think I'm doing this wrong. All the data and values and being read correctly but I get this error code:

'Error: Commands out of sync; you can't run this command now'

Could someone point me in the right direction with this one please =)

Aero204
  • 99
  • 10
  • Take a look at this: http://stackoverflow.com/questions/16339628/why-i-am-getting-the-error-commands-out-of-sync-you-cant-run-this-command-now – Noman Ghani Apr 11 '14 at 08:11

1 Answers1

1

Did you try running two sql queries as separate statements? rather than keeping them in 1 SQL string variable?

kk497055
  • 116
  • 8