脚本更改管理员密码

时间:2016-03-05 17:01:41

标签: php user-input insert-update

我编写了一个脚本来通过输入更改管理员密码 但问题是当我写新密码时。 它改变了所有表格,这意味着新密码成为所有用户的新密码,我只希望它为我选择的用户 如果你能帮帮我的话 这是剧本:

                  <form method="post">
                   <div style="padding-left:40px;" class="azer" class="adm">
                    <ul style="list-style : none; " >
                        <li style="padding-left:5px;">
                            <h6  style="float:left; ">new password :</h6>                           
                            <input  style="float:left; margin-left:10px; " type="text" name="zd_pass"  placeholder="*******"> 
                        </li>
                        <li><input style="margin-left:10px;" type="submit" name="save" value="save" class="btn btn-info" ></li>
                    </ul>
                </div>
            </form>
           <?php             
if(isset($_GET['id'])){
    $id = (int)$_GET['id'];
    $get_id = "select * from admin where zd_id='$id'";
    $run_id = mysqli_query($db,$get_id);
    if(mysqli_num_rows($run_id) > 0){
      if(isset($_POST['save'])){    
               $zd_id = @$_POST['zd_id'];   
               $zd_pass = @$_POST['zd_pass'];
          $update = "update admin set zd_pass='$zd_pass'";
          $run_update = mysqli_query($db,$update);
   if(isset($run_update)){
  }}   }}  ?>

1 个答案:

答案 0 :(得分:2)

您需要将更新限制为单行,就像使用上一个选择一样。您可以通过设置这样的WHERE子句来完成此操作,否则它将更新整个数据库。

在将更新提交到数据库执行后,您的测试也不可靠。您应该按以下方式更改

$update = "update admin set zd_pass='$zd_pass' WHERE zd_id='$id'";

$run_update = mysqli_query($db,$update);
if( $run_update !== FALSE) {
    // the update worked
} else {
    // the update failed
}