Marc
Marc

Reputation: 29

Mysql update with two tables not working

The solution - include get variable in the form tag's action attribute. The problem is calling the primary key and I've tried $id = $_GET['ID']; and it fails. With $id = 1 and it works perfectly. I've tried $id = (isset($_GET['ID'])); as well fails. Got it working and thanks to you all

  <?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);

 ?>

Upvotes: 1

Views: 79

Answers (1)

Indra Prakash Tiwari
Indra Prakash Tiwari

Reputation: 1057

i think you have missed T1.ID = T2.ID, please try below one

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=?

Upvotes: 1

Related Questions