I have tried to add die("The passwords don't match"); also insted of echo. But this still seems to not do anything at all when register is clicked. The variable names match the ones in the contact form perfectly. I can only think of one thing. Might sound funny It it because I'm already logged in (registered)?. I'm sorry if thsi question has been answered but I did not see any answer that helped me with someone in a similar situation. Cheers!
<?php
require('inc/phpfunctions.php');
if(isset($_POST['submit'])){
//perform the verification
$email1 = $_POST['email1'];
$email2 = $_POST['email2'];
$pass1 = $_POST['pass1'];
$pass2 = $_POST['pass2'];
if ($email1 == $email2){
if($pass1 == $pass2){
//All good. Carry On.
}else{
echo "Sorry your passwords do not match. <br />";
exit();
}
}else{
echo "Sorry your email's do not match<br /><br />";
}
}else{
$form = <<<EOT
<form action="register.php" method="POST">
First Name: <input type= "text" name="name" /><br />
Last Name: <input type= "text" name="lname" /><br />
Username: <input type= "text" name="uname" /><br />
Email: <input type= "text" name="email1" /><br />
Confirm Email: <input type= "text" name="email2" /><br />
Password: <input type= "password" name="pass1" /><br />
Confirm Password: <input type= "password" name="pass2" /><br />
<input type="submit" value="Register" name"submit" />
</form>
EOT;
echo $form;
}
?>
Based on your code, your main issue is that you are missing an equal sign in your form name="submit"
. Here is a reorganization of what you have with notations:
// Establish fail by default
$success = false;
if(isset($_POST['submit'])){
// Create a function that will match input values
function MatchVars($var1,$var2)
{
if(empty($var1) || empty($var2))
return 0;
return ($var1 == $var2)? 1 : 0;
}
// Store error/success
$validate['email'] = MatchVars($_POST['email1'],$_POST['email2']);
$validate['pass'] = MatchVars($_POST['pass1'],$_POST['pass2']);
// Check each for individual error
if($validate['email'] != 1)
echo 'Emails do not match!';
if($validate['pass'] != 1)
echo 'Passwords do not match!';
// Assign success or fail based on the sum of the validate array
// Less than 2 is fail. This will overwrite the first established
// instance of the $success variable
$success = (array_sum($validate) == 2)? true:false;
}
if($success == false) {
// the name="submit" is missing and equal sign
// Since you are basing your forward movement on that variable
// if it's "broken," the if/else will not work
$form = <<<EOT
<form action="" method="POST">
First Name: <input type= "text" name="name" /><br />
Last Name: <input type= "text" name="lname" /><br />
Username: <input type= "text" name="uname" /><br />
Email: <input type= "text" name="email1" /><br />
Confirm Email: <input type= "text" name="email2" /><br />
Password: <input type= "password" name="pass1" /><br />
Confirm Password: <input type= "password" name="pass2" /><br />
<input type="submit" value="Register" name="submit" />
</form>
EOT;
echo $form;
}