尝试让页面动态显示密码是否匹配(echo'Match'或'Do not match')。 (与上一个问题类似here。)
查看密码1和密码2是否与您在“密码”或“确认密码”输入框中输入的内容相同。
编辑:似乎elseif($ password2 == $ password1)没有像我预期的那样检查匹配。发布password1和password2可以正常工作(当您在任一输入框中键入时,#feedback会更改为“不匹配”,但“匹配”从不显示)。有关如何修复此代码的任何帮助表示赞赏。
check.php
<?php
include __DIR__ . '/mysqli_connect.php';
$password2 = mysqli_real_escape_string($dbc, $_POST['password2']);
$password1 = mysqli_real_escape_string($dbc, $_POST['password1']);
if ($password2==NULL && $password1==NULL) {
echo '';
} elseif ($password2 == $password1) {
echo 'Match';
} else {
echo 'Do not match';
}
register.php
<script type="text/javascript" src="/jquery-3.2.1.min.js"></script>
<script>
$(document).ready(function() {
$('#feedback').load('/includes/check.php').show();
$('#password1').keyup(function() {
$.post('/includes/check.php', { password1: form.password1.value },
function(result) {
$('#feedback').html(result).show;
});
});
});
$(document).ready(function() {
$('#feedback').load('/includes/check.php').show();
$('#password2').keyup(function() {
$.post('/includes/check.php', { password2: form.password2.value },
function(result) {
$('#feedback').html(result).show;
});
});
});
</script>
<form action="register.php" method="post" name="form">
<input id="password1" class="signup_input_box" type="password" name="password1" maxlength="20" value="<?php if (isset($trimmed['password1'])) echo $trimmed['password1']; ?>">
<input id="password2" class="signup_input_box" type="password" name="password2" maxlength="20" value="<?php if (isset($trimmed['password2'])) echo $trimmed['password2']; ?>">
<div id="feedback"></div>
<p><center><input type="submit" name="submit" value="Register"></center>
</form>