密码不会更新,但临时代码会更新!? PHP邮件,用户忘记密码

时间:2014-11-10 18:01:28

标签: php sql passwords

我制作了一个webapp,我需要让用户更改密码,所以我创建了一个包含临时代码的列。问题是,我的查询确实更新了我的临时代码,但不会将密码更新为新密码。请提前帮助,谢谢! ;)

<?php
   if(isset($_POST['submit'])) {
     $code = $_SESSION['code'];
     $email = $_SESSION['emailneger'];
     $password = $_POST['password2'];
     $password1 = $_POST['password3'];
     $reset = $_POST['reset'];
     $tempcode = "";
     if($reset == $reset) {
       if($password == $password1) {
         $query =  "UPDATE consultant SET password = ?
                    AND tempcode = ?
                    WHERE email =  ? ";
         $qry=$db->prepare($query);
         $qry->execute(array($password, $code, $email));
         echo "<p>Uw wachtwoord is hersteld!</p>";
         $query = 'UPDATE consultant SET tempcode = ? WHERE email = ?';
         $qry=$db->prepare($query);
         $qry->execute(array($tempcode, $email));
       }  else {
         echo "<p>Wachtwoorden komen niet overeen.</p>";
       }
     } else {
       echo "<p>Je link is ongeldig, probeer nogmaals alstublieft!</p>";
     }
   }
?>

1 个答案:

答案 0 :(得分:1)

您的更新不正确。语法是

UPDATE yourtable SET field1=value1, field2=value, ...
                                  ^---

注意字段/值对之间的,。您正在使用AND,它将被解析/执行为

UPDATE consultant SET password = (? AND tempcode = ?) WHERE email =  ? 
UPDATE consultant SET password = ('foo' AND tempcode=123) WHERE email = 'foo@example.com')
UPDATE consultant SET password = ('foo' AND true/false) WHERE ...
UPDATE consultant SET password = true/false WHERE ...