A little trouble validating register form...

Discussion in 'PHP' started by scottlpool2003, Sep 7, 2012.

  1. #1
    Having a little trouble validating the email address using FILTER_VALIDATE_EMAIL

    It's outputting that the email address is in the wrong...

    FORM
    <form action="register.php" method="post">
    <label>Username</label>
    <input type="text" name="username">
    <label>Email Address</label>
    <input type="text" name="useremail">
    <label>Password</label>
    <input type="password" name="password">
    <label>Repeat Password</label>
    <input type="password" name="password2">
    <input type="submit" class="loginsubmit" value="Register" name="submitb">
    </form>
    HTML:

    PHP
    <?php
    
    //check if the submit button has been hit
    if (isset($_POST['submitb'])) { 
    
    //post variables from form
    $useremail = $_POST["useremail"];
    $username = $_POST["username"];
    $password = $_POST["password"];
    $password2 = $_POST["password2"];
    
    //check if email is valid format
    if (filter_var($email, FILTER_VALIDATE_EMAIL)) {
    
    $emailcheck = "email is correct format";
    
    }
    
    else { 
    $emailcheck = "email is incorrect format";
    }
    
    
    //check if both password fields contain the same password
    if ($password == $password2) {
    $passwordcheck = "passwords are the same";
    }
    else {
    $passwordcheck = "passwords dont match!";
    }
    }
    ?>
    <?php include"../includes/head.php";?>
    <?php echo "$passwordcheck<br />$emailcheck";?>
    
    
    
       <?php include"../includes/footer.php";?>
    
    PHP:
     
    scottlpool2003, Sep 7, 2012 IP
  2. scottlpool2003

    scottlpool2003 Well-Known Member

    Messages:
    1,708
    Likes Received:
    49
    Best Answers:
    9
    Trophy Points:
    150
    #2
    Oooops!

    I'm trying to check $email instead of $useremail.

    Solved.
     
    scottlpool2003, Sep 7, 2012 IP