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

<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
}
}
?>
new file
<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>
Preview
Clear
- Course Recommendations
- Courseware download
The courseware is not available for download at the moment. The staff is currently organizing it. Please pay more attention to this course in the future~
Students who have watched this course are also learning
Let's briefly talk about starting a business in PHP
Quick introduction to web front-end development
Large-scale practical Tianlongbabu development of Mini version MVC framework imitating the encyclopedia website of embarrassing things
Getting Started with PHP Practical Development: PHP Quick Creation [Small Business Forum]
Login verification and classic message board
Computer network knowledge collection
Quick Start Node.JS Full Version
The front-end course that understands you best: HTML5/CSS3/ES6/NPM/Vue/...[Original]
Write your own PHP MVC framework (40 chapters in depth/big details/must read for newbies to advance)
















