if(isset($_POST['submitRegister'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$password2 = $_POST['password2'];
$email = $_POST['email'];
if(!preg_match('#^[a-zA-Z0-9_-]+$#', $username))
$error1 = 'Username can only contain: A-Z a-z 0-9 _ - ';
if(!isset($username) || empty($username))
$error1 = 'Please enter your Username';
if(!preg_match("#[0-9]+#", $password))
$error2 = 'Password must include at least one number';
if(!isset($password) || empty($password))
$error2 = 'Please enter your Password';
if($password != $password2)
$error3 = 'Passwords do not match';
if(!isset($password2) || empty($password2))
$error3 = 'Please confirm your Password';
if(!preg_match("#^[a-z0-9._%+-]+@[a-z0-9.-]+\.[a-z]{2,4}+$#", $email))
$error4 = 'That e-mail does not appear to be valid';
if(!isset($email) || empty($email))
$error4 = 'Please enter your E-mail address';
if(!isset($_POST["terms"]))
$error5 = 'You must accept the Terms and Conditions';
else {
require_once 'server.php';
require_once 'dbconn.php';
}
}
I'm having some trouble in getting this to work correctly. As you can see I have multiple if conditions. In fact there are a few more, but I've edited it to make the post a bit shorter. I've gone through lots of if else tuts and thought I understood it, but clearly not.
My problem is, as long as I don't tick the terms checkbox (the last if statement), everything works fine. But if I tick the checkbox, it will attempt to connect to the database, regardless if the previous fields are empty or not filled in correctly.
Thinking upon my last post where I had put my ifs in the wrong order (back to front), I placed the if statement for the terms first and the username one last. I thought this solved it, but so long as I put in a username it would connect, regardless if the other fields were empty. So that did not work in this case. Hoping someone can help, many thanks.
elseif
in there...