Trying to get page to dynamically show if passwords match (echo 'Match' or 'Do not match'). (Similiar to previous question asked here.)
Looking to check if password1 and password2 are the same as you type in either the 'password' or 'confirm password' input boxes.
EDIT: Seems elseif ($password2 == $password1) isn't checking for the match as I intended. Posting of password1 and password2 works (#feedback changes to 'Do not match' as you type in either input box, but 'Match' never shows). Any help on how to fix this code is appreciated.
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>