PHP develops si...LOGIN

PHP develops simple book background management system password change function

We completed the administrator password modification page in the previous section

This section will implement this function

1622.png

##Need to give <input type = submit> ;Add an onClick event

Use javascript to determine the original password, new password, and confirm the new password. All of them must be empty. The new password and the confirmed password must be consistent.

<script type="text/javascript">
  function checkspace(checkstr) {
    var str = '';
    for(i = 0; i < checkstr.length; i++) {
      str = str + ' ';
    }
    return (str == checkstr);
  }
  function check()
  {
    if(checkspace(document.renpassword.password.value)) {
      document.renpassword.password.focus();
      alert("原密码不能为空!");
      return false;
    }
    if(checkspace(document.renpassword.password1.value)) {
      document.renpassword.password1.focus();
      alert("新密码不能为空!");
      return false;
    }
    if(checkspace(document.renpassword.password2.value)) {
      document.renpassword.password2.focus();
      alert("确认密码不能为空!");
      return false;
    }
    if(document.renpassword.password1.value != document.renpassword.password2.value) {
      document.renpassword.password1.focus();
      document.renpassword.password1.value = '';
      document.renpassword.password2.value = '';
      alert("新密码和确认密码不相同,请重新输入");
      return false;
    }
    document.admininfo.submit();
  }
</script>

Use the database SQL statement to query whether the original password entered matches the password filled in the text box

If the match is successful, the modification function of the SQL statement will be used to modify the password in the database After the password

is successfully modified, return to the login page and log in again using the new password.

<?php
$password=$_SESSION["pwd"];
$sql="select * from admin where password='$password'";
$rs=mysqli_query($link,$sql);
$rows=mysqli_fetch_assoc($rs);
$submit = isset($_POST["Submit"])?$_POST["Submit"]:"";
if($submit)
{
  if($rows["password"]==$_POST["password"])
  {
    $password2=$_POST["password2"];
    $sql="update admin set password='$password2' where id=1";
    mysqli_query($link,$sql);
    echo "<script>alert('修改成功,请重新进行登陆!');window.location='login.php'</script>";
    exit();
  }
  else
    ?>
    <?php
  {
    ?>
    <script>
      alert("原始密码不正确,请重新输入")
      location.href="renpassword.php";
    </script>
    <?php
  }
}
?>


Next Section

<script type="text/javascript"> function checkspace(checkstr) { var str = ''; for(i = 0; i < checkstr.length; i++) { str = str + ' '; } return (str == checkstr); } function check() { if(checkspace(document.renpassword.password.value)) { document.renpassword.password.focus(); alert("原密码不能为空!"); return false; } if(checkspace(document.renpassword.password1.value)) { document.renpassword.password1.focus(); alert("新密码不能为空!"); return false; } if(checkspace(document.renpassword.password2.value)) { document.renpassword.password2.focus(); alert("确认密码不能为空!"); return false; } if(document.renpassword.password1.value != document.renpassword.password2.value) { document.renpassword.password1.focus(); document.renpassword.password1.value = ''; document.renpassword.password2.value = ''; alert("新密码和确认密码不相同,请重新输入"); return false; } document.admininfo.submit(); } </script>
submitReset Code
ChapterCourseware