I am trying to update three table of mysql database. i tried two ways but its not happening.The thing is, someone can check my database table and see the relation and then check my query either it works or not My tables are as follows:
projects | students | progress
============================================
Pk ProjectID | PK RegNo | PK ProgressID
ProjectTitle | Name | FK RegNo
| FK ProjectID |
I tried different ways to achieve my updation.
$query= "UPDATE progress SET RegNo='$s1_id'
WHERE RegNo IN(SELECT RegNo FROM students WHERE ProjectID = '$id');
UPDATE students SET RegNo='$s1_id', Name='$s1_name'
WHERE ProjectID = '$id';
UPDATE projects SET ProjectTitle='$ptitle'
WHERE ProjectID='$id';";
2nd Way
$query = "UPDATE projects
INNER JOIN students ON students.ProjectID = projects.ProjectID
INNER JOIN progress ON students.RegNo = progress.RegNo
SET projects.ProjectTitle = '$ptitle',
students.RegNo = '$s1_id',
students.Name = '$s1_name' ,
progress.RegNo = '$s1_id'
WHERE projects.ProjectID = '$id' ";
try
{
$stmt = $conn->prepare( $query );
$result = $stmt->execute();
$msg = "Record updated";
header("location:adminhome.php");
}
catch(PDOException $ex)
{
$msg = $ex -> getMessage();
}