要插入错误的事务

时间:2018-02-24 23:58:20

标签: php mysql mysqli

我已经阅读了许多问题尝试了许多不同的方法,但没有成功。 我想插入多个表。 我有一个交易,但它抛出错误:

  Warning: mysqli_query(): Empty query on the  lines  

起始

  if ($result).

我想我错过了一些简单的事情。这真的让我觉得我必须花一个星期的时间来解决这个问题。 我的表都是innodb,所有列数据类型都匹配。 我可以进行单独的插入,但不能进行多次插入。

 <?php

 $jid = $_REQUEST['JID'];
 $CLx = $_REQUEST['CL'];
 $CL = str_replace("'", "\'", $CLx);
 $ADx = $_REQUEST['AD'];
 $AD = str_replace("'", "\'", $ADx);
 $DT = $_REQUEST['DT'];
 $SS1 = $_REQUEST['SS1'];
 $SS2 = $_REQUEST['SS2'];
 $SS3 = $_REQUEST['SS3'];
 $SVFNx = $_REQUEST['SVFN'];
 $SVFN = str_replace("'", "\'", $SVFNx);
 $CS = $_REQUEST['CS'];
 $OFTC = $_REQUEST['OFTC'];
 $SV = $_REQUEST['SV'];



 $dbConnection = mysqli_connect ('10.169.999.999', 'boiw', 'Tx', 'bw1_pp');

 mysqli_autocommit($dbConnection, false);

 $flag =true;

  $squery1 = "INSERT INTO `awg` (`JID`,`CL`,`AD`,`DT`,`SS1`,`SS2`,`SS3`,`SVFN`,`CS) VALUES ($jid,$CL,$AD,$DT,$SS1,$SS2,$SS3,$SVFN,$CS)";
  $squery2 = "INSERT INTO `cae` (`JID`,`CL`,`AD`,`DT`,`SS1`,`SS2`,`SS3`,`SVFN`) VALUES ($jid,$CL,$AD,$DT,$SS1,$SS2,$SS3,$SVFN)";
  $squery3 = "INSERT INTO `calc` (`JID`,`CL`,`AD`,`DT`,`SS1`,`SS2`,`SS3`,`SVFN`) VALUES ($jid,$CL,$AD,$DT,$SS1,$SS2,$SS3,$SVFN)";
  $squery4 = "INSERT INTO `costings` (`JID`,`CL`,`AD`,`DT`,`SS1`,`SS2`,`SS3`,`SVFN`) VALUES ($jid,$CL,$AD,$DT,$SS1,$SS2,$SS3,$SVFN,$CS)";
  $squery5 = "INSERT INTO `hazzard` (`JID`,`CL`,`AD`,`DT`,`SS1`,`SVFN`,`CS`) VALUES ($jid,$CL,$AD,$DT,$SS1,$SVFN,$CS)";
  $squery6 = "INSERT INTO `spay` (`JID`,`CL`,`AD`,`DT`,`SS1`,`SS2`,`SS3`,`SVFN`,`surveyor`) VALUES ($jid,$CL,$AD,$DT,$SS1,$SS2,$SS3,$SVFN,$SV)";
  $squery7 = "INSERT INTO `spix` (`JID`,`CL`,`AD`,`DT`,`SS1`,`SVFN`,) VALUES ($jid,$CL,$AD,$DT,$SS1,$SVFN)";
  // I have tried stating the values as $X, '$X',....no difference
  $result = mysqli_query($dbConnection, $query1);

  if (!$result) {
  $flag = false; 
  echo "Error details: " . mysqli_error($dbConnection) . ".";
  }

  $result = mysqli_query($dbConnection, $query2);

  if (!$result) {
  $flag = false; 
  echo "Error details: " . mysqli_error($dbConnection) . ".";
  }

  $result = mysqli_query($dbConnection, $query3);  // and so on

  if (!$result) {
  $flag = false; 
  echo "Error details: " . mysqli_error($dbConnection) . ".";
  }

  if ($flag) {
  mysqli_commit($dbConnection);
  echo "All queries were executed successfully";
  } else {
  mysqli_rollback($dbConnection);
  echo "All queries were rolled back";
  }

  mysqli_close($dbConnection);

  ?>

0 个答案:

没有答案