两个表无效的Mysql更新

时间:2015-09-04 03:20:19

标签: mysql

解决方案 - 在表单标记的action属性中包含get变量。问题是调用主键,我尝试过$ id = $ _GET ['ID'];它失败了。 $ id = 1,效果很好。我试过$ id =(isset($ _ GET ['ID']));也失败了。工作得很好,谢谢大家

  <?php

  include 'Includes/conDB.php';

  if ($_SERVER["REQUEST_METHOD"] == "POST") {

   $unoone = $_POST['stringone'];
   $unotwo = $_POST['stringtwo'];
   $unothree = $_POST['integerthree'];
   $unofour = $_POST['stringfour'];

   // a data path for images  
    $valuz_ins = explode(',', $valuz_ins);

   $id = $_GET['ID'];

   $result = "UPDATE T1 LEFT JOIN T2
   ON (T1.ID=T2.ID) SET T1.stringone=?, 

   T1.stringtwo=?, T1.integerthree=?, T1.stringfour=?,  
   T2.imge1=?, T2.imge2=?, T2.imge3=?, T2.imge4=?
   WHERE T1ID=?"; 

   // prepare and bind

   $stmt = mysqli_prepare($con,$result);

  mysqli_stmt_bind_param($stmt,'ssisssssi', $unoone, $unotwo, 

  $unothree, $unofour, $valuz_ins[0], $valuz_ins[1], $valuz_ins[2],             
   $valuz_ins[3], $id);

 /* execute prepared statement */
 mysqli_stmt_execute($stmt);


 printf("%d Record updated.\n", mysqli_stmt_affected_rows($stmt));


 } 
 /* close statement and connection */
 mysqli_stmt_close($stmt);

 mysqli_close($con);

 ?>

1 个答案:

答案 0 :(得分:1)

我认为您错过了T1.ID = T2.ID,请尝试以下

UPDATE T1 LEFT JOIN T2
   ON (T1.ID=T2.ID) SET T1.stringone=?, 

   T1.stringtwo=?, T1.integerthree=?, T1.stringfour=?,  
   T2.imge1=?, T2.imge2=?, T2.imge3=?, T2.imge4=?
   WHERE T1.ID=?