嗨,我们正在进行注册更新。我已经使编码和密码必须与确认密码更新相同。我已经试过了。它出现"请检查密码并确认密码"在警报框中。但是当我检查数据库时,确认密码仍在数据库中。示例密码:admin01但是userconfirm:admin02。如果密码不等于确认密码,我该如何停止该过程。谢谢
<?php
session_start();
?>
<?php
include('config1.php');
$username=$_SESSION['username'];
$userid=$_POST['userid'];
$useremail=$_POST['useremail'];
$userdiv=$_POST['userdiv'];
$userdepartment=$_POST['userdepartment'];
$userpass=$_POST['userpass'];
$userconfirm=$_POST['userconfirm'];
// update data in mysql database
$sql="UPDATE login SET userid='$userid', useremail='$useremail', userdiv='$userdiv', userdepartment='$userdepartment', userpass='$userpass',userconfirm='$userconfirm' WHERE username='$username'";
$result=mysql_query($sql);
if($result)
{
if ($_POST['userpass'] == $_POST['userconfirm'])
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('UPDATE SUCCESS')
window.location.href='userMain.php';
exit();
</SCRIPT>");
}
else
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('PLEASE CHECK YOUR PASSWORD AND CONFIRM PASSWORD')
window.location.href='updateUser.php';
exit();
</SCRIPT>");
}
}
else
{
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('UPDATE ERROR ')
window.location.href='updateUser.php';
exit();
</SCRIPT>");
}
?>
我认为必须把其他东西放在正确的位置?如果密码!=确认密码
,我不知道要结束这个过程答案 0 :(得分:0)
问题是您首先更新数据库,然后验证密码是否不匹配。您必须先验证,如果一切正常,请更新数据库。
你必须注意的另一件事是:
mysql_
函数已弃用,请改用PDO
或mysqli_
函数。代码示例:
if ($_POST['userpass'] != $_POST['userconfirm']) {
die("<SCRIPT LANGUAGE='JavaScript'>
window.alert('PLEASE CHECK YOUR PASSWORD AND CONFIRM PASSWORD');
window.location.href='updateUser.php';
</SCRIPT>");
}
$userid = mysql_real_escape_string($_POST['userid']);
// ... put all the variables here
$sql="UPDATE login
SET userid='$userid'
, useremail='$useremail'
, userdiv='$userdiv'
, userdepartment='$userdepartment'
, userpass='$userpass'
, userconfirm='$userconfirm'
WHERE username='$username'";
if(!mysql_query($sql)) {
die("<SCRIPT LANGUAGE='JavaScript'>
window.alert('UPDATE ERROR');
window.location.href='updateUser.php';
</SCRIPT>");
}
echo "<SCRIPT LANGUAGE='JavaScript'>
window.alert('UPDATE SUCCESS');
window.location.href='userMain.php';
</SCRIPT>");