i need to update two table at a time using MySQL and PHP.I am explaining my code below.
update.php:
<?php
$postdata = file_get_contents("php://input");
$request = json_decode($postdata);
$dept_list=$request->dept_name;
$hod_name=$request->hod_name;
$email=$request->email;
$password=$request->password;
$hod_id=$request->hod_id;
$con = mysql_connect('localhost', 'root', 'Oditek123@');
mysql_select_db('go_fasto', $con);
$qry = "UPDATE db_deptHead SET dept_list='$dept_list', hod_name='$hod_name', emailid='$email' password='$password' WHERE hod_id='$hod_id'";
$qry_res = mysql_query($qry);
if($qry_res){
echo "HOD data updated successfully";
}else{
echo "HOD data could not updated";
}
?>
Here i am updating one table i.e-db_deptHead
.i need to update another table(db_Admin
) with field name email_id and password
with same value.As email and password values are always same so i need to update both table.Please help me.
It should be possible with a multi-table update, as described in the documentation.
http://dev.mysql.com/doc/refman/5.5/en/update.html
UPDATE Table_One a INNER JOIN Table_Two b ON (a.col1 = b.col1)
SET
a.win = a.win+1, a.streak = a.streak+1, a.score = a.score+200,
b.win = b.win+1, b.streak = b.streak+1, b.score = b.score+200
WHERE a.userid = 1 AND a.lid = 1 AND b.userid = 1
Note: Multi-table doesn't support LIMIT, so this could cause more grief depending on the details.
Stored procedures or transactions may be a nicer solution.