2017-04-22 102 views
0

我想更新兩個表,當我使用提交表單。我使用此代碼,但只更新一個表。如何更新兩者?PHP PDO更新兩個表

$cryptpass = password_hash($password, PASSWORD_BCRYPT, array("cost" => 12)); 
$db = DB(); 
$query = $db->prepare("UPDATE passrecovery SET resComplete = 'Yes' WHERE email = :email"); 
$query->closeCursor(); 
$query = $db->prepare("UPDATE members SET password = :cryptpass WHERE email = :email"); 
$query->execute(array(
    ':email' => $row['email'], 
    ':cryptpass' => $cryptpass, 
)); 
print_r("<div class='success'>Success</div>"); 
+1

你忘了'執行()'第一個查詢。 –

+0

是的,他忘了它,但爲什麼2更新?這是沒有必要的。 –

回答

0
$cryptpass = password_hash($password, PASSWORD_BCRYPT, array("cost" => 12)); 
$db = DB(); 
$query = $db->prepare("UPDATE passrecovery p, members m 
SET p.resComplete = 'Yes', m.password = :cryptpass 
WHERE p.email = m.email and p.email = :email"); 
$query->execute(array(
    ':email' => $row['email'], 
    ':cryptpass' => $cryptpass, 
)); 
print_r("<div class='success'>Success</div>");