I tried this code the and thing is for some reason it it gets stuck at this point
if (!$POST['password1'] !== $POST['password2'] || empty($_POST['password1'])) {
echo 'Your passwords do not match Or you did not enter a password. Please enter again';
because I enter the password and made sure its the same password each time but when I click the submit button it keeps printing "'Your passwords do not match Or you did not enter a password. Please enter again" even though the two passwords are the same I made sure all the variables are the same and all the text box names are the same so I dunno what else the problem maybe
<?php
if ($_POST['submitForm']) {
if (!$_POST['password1'] !== $_POST['password2'] || empty($_POST['password1'])) {
echo 'Your passwords do not match Or you did not enter a password. Please enter again';
} elseif (!empty($_POST['fname']) && !empty($_POST['sname']) && !empty($_POST['uname'])) {
$conn = mysql_connect("localhost","root","") or die("Could Not Connect To The Database");
mysql_select_db("database",$conn) or die("Could Not Select The Database");
$res = mysql_query("SELECT username FROM passwordtable WHERE username='$_POST[uname]'",$conn) or die("Query Failed");
$exists = mysql_num_rows($res);
if ($exists !== 0) {
echo 'That Username Already Exists In The Database. Please Choose Another User Name Thank You.';
} else {
$sql = "INSERT INTO passwordtable (user_id,firstname,surname,username,password) VALUES ('','$_POST[fname]','$_POST[sname]','$_POST[uname]','$_POST[password1]')";
$query = mysql_query($sql,$conn) or die(mysql_error("Could Not Write Information To The Database"));
if (mysql_affected_rows($conn) == 0) {
echo 'Your Account Was Not Created.';
} else {
echo 'Your Account Was Created Successfully';
}
}
}
}
?>
<p align="center"><form action="register.php" method="post" >
<p><STRONG>First Name:</STRONG><br>
<input type="text" name="fname" maxlength="20"></p>
<p><STRONG>Surname:</STRONG><br>
<input type="text" name="sname" maxlength="20"></p>
<p><STRONG>User Name:</STRONG><br>
<input type="text" name="uname" maxlength="20"></p>
<p><STRONG>Password:</STRONG><br>
<input type="password" name="password1" maxlength="32"></p>
<p><STRONG>Confirm Password:</STRONG><br>
<input type="password" name="password2" maxlength="32"></p>
<p><input type="submit" name="submitForm" value="Register User"></p>
</form>
</p>
This is what I done but it still doesn't seem to work even though I enter the same password it still comes up with "'Your passwords do not match Or you did not enter a password. Please enter again" so I hope anyone can help me to find what the problem is it would be great
Thank you so much 🙂