dounan9070 2013-01-30 21:10
浏览 45

如何检查表中是否更新了密码

I writing a script in php to reset user's password, and how do I check if password is updated in a table? For example, if a data in tuple has been changed, then send email. Please check comments in the script.

 $dbcc = mysqli_connect(HOST,NAME,PASSWORD,DATABASE) or die('Error can not connect to database');

 $query = "SELECT uid,email FROM `corporate` WHERE (email='$chk_email')";
 $result = mysqli_query($dbc, $query);

 //found
 if(@mysqli_num_rows($result) == 1)
 {
                    $ROW = mysqli_fetch_array($result);
                    $sent_email = $ROW['email']; //get email
                    $id = $ROW['uid'];           //get uid

                    $new_password = generatePassword(8);//generates 8 char long random password 
                    $enc_password = md5($new_password); //encrypt

                    $statement = "UPDATE corpoorate SET password=".$enc_password." WHERE uid ='$id'";
                    $go = mysqli_query($dbcc,$statement) or die(mysqli_error());
                    mysqli_close($dbcc);

                       /*
                        * HOW DO I CHECK IF PASSWORD IS UPDATED IN THE DATABASE?
                        * IF IT IS, SEND EMAIL
                                                    * IF $go==true does not work!
                        **/
                    if($go==true){
                    $sendmessage = "We have generated a new password token for you.
 Your password is reset to ".$new_password." 
 Please note that this password is not secure. Once you login, please reset your password.
 ";

                     mail($sent_email,'Password Reset',$sendmessage,'From: address@gmail.com');     
                                                                                    }                   

                     header("Location : http://limozoor.com/login/signin.php");
                     exit();    
        }//if
        mysqli_close($dbcc);
  • 写回答

2条回答 默认 最新

  • douyong1885 2013-01-30 21:13
    关注

    Because of your or die(mysqli_error());-condition the password will always be updated in the table if it reaches those lines of execution.

    However, I am sceptic towards your if(@mysqli_num_rows($resultt) == 1) because if there is any error in your first SQL-query, you are supressing all error messages there (by using @), which makes me think that you never even try to execute the UPDATE statements.

    评论

报告相同问题?

悬赏问题

  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 关于#java#的问题:找一份能快速看完mooc视频的代码
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码
  • ¥20 用HslCommunication 连接欧姆龙 plc有时会连接失败。报异常为“未知错误”
  • ¥15 网络设备配置与管理这个该怎么弄
  • ¥20 机器学习能否像多层线性模型一样处理嵌套数据
  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题