Reputation: 13
I have a page called update.php and what i want to do is that i want to update a record a record in two tables at the same time.what i have here now is just updating in a single table, can anyone please help me with it?
****here is my code for class.user.php**
public function update($user_id,$username,$password,$province)
{
try
{
$stmt=$this->db->prepare("UPDATE login SET username=:username,password=:password,province=:province WHERE user_id=:user_id");
$stmt->bindparam(":username",$username);
$stmt->bindparam(":password",$password);
$stmt->bindparam(":province",$province);
$stmt->execute();
return true;
}
catch(PDOException $e)
{
echo $e->getMessage();
return false;
}
}
and here is now for update.php
include_once 'dbconfig.php';
if(isset($_POST['btn-update']))
{
$ID = $_GET['ID'];
$username = $_POST['username'];
$password = $_POST['password'];
$province = $_POST['province'];
if($crud->update($ID,$username,$password,$province))
{
echo "<script type='text/javascript'>alert('Successfully Updated!');</script>";
}
else
{
echo "<script type='text/javascript'>alert('Updating Failed!'); </script>";
}
}
if(isset($_GET['ID']))
{
$ID = $_GET['ID'];
extract($crud->getID($ID));
}
?>
Upvotes: 0
Views: 966
Reputation: 5444
Try this..
UPDATE login, login2
SET login.username = :username,
login.password = :password,
login.province = :province,
login2.username = :username,
login2.contacts = :contacts
WHERE login.user_id = :user_id and login2.user_id = :user_id ;
Upvotes: 1