扫码关注官方订阅号
代码是按照http://blog.csdn.net/qazcxh/article/details/45726911这里写的,现在的问题是,输入错误的密码后,会提示密码错误,但是数据库会更新新的密码,请教各位怎么修改
php程序在显示内容之后,依然会继续执行,一直到碰到die()、exit()之类的终止或者一直到执行完。所以处理你的问题有两种方法
1.判断之后加die2.把判断之后的代码放到else里面
if ($oldpassword!=$dbpassword) {
?>
<script type="text/javascript">
alert("密码错误");
window.location.href="changepasswd.html";
</script>
<?php
mysql_query ( "update t_account set password='{$newpassword}' where username='{$username}'" ) or die ( "存入数据库失败" . mysql_error () );//如果上述用户名密码判定不错,则update进数据库中
}
mysql_close ( $con );
这样你吧更新语句放外面,无论什么密码都会更新啊= = 还有 mysql不要用了尽量使用mysqli吧
最简单的方法就是
在密码判断内判断密码错误之后 加die;终止程序
微信扫码关注PHP中文网服务号
QQ扫码加入技术交流群
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号
PHP学习
技术支持
返回顶部
php程序在显示内容之后,依然会继续执行,一直到碰到die()、exit()之类的终止或者一直到执行完。
所以处理你的问题有两种方法
1.判断之后加die
2.把判断之后的代码放到else里面
if ($oldpassword!=$dbpassword) {
?>
<script type="text/javascript">
alert("密码错误");
window.location.href="changepasswd.html";
</script>
<?php
mysql_query ( "update t_account set password='{$newpassword}' where username='{$username}'" ) or die ( "存入数据库失败" . mysql_error () );//如果上述用户名密码判定不错,则update进数据库中
}
mysql_close ( $con );
?>
最简单的方法就是
在密码判断内判断密码错误之后 加die;终止程序