SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Guru
    Join Date
    Feb 2007
    2 Post(s)
    0 Thread(s)

    2 of 3 Error Messages Not Working


    I have created a login code which adds the firstname and surname to the database. However when the cells are left blank they do not provide the first 2 error messages below. However the 3rd error messages works. Does anyone have any suggestions why the first two error messages dont work.

        if(isset($_POST['registerSubmit']) && $_POST['registerSubmit'] == 'true'){
        $firstname = mysql_real_escape_string(trim($_POST['firstname']));
        $surname = mysql_real_escape_string(trim($_POST['surname']));
            $registerEmail = trim($_POST['email']);  
            $registerPassword = trim($_POST['password']);  
            $registerConfirmPassword    = trim($_POST['confirmPassword']);  
        if(!isset($firstname) || empty($firstname)) {
            $error = "Please enter your First Name.";
    	if(!isset($surname) || empty($surname)) {
            $error = "Please enter your Surname.";
            if(strlen($registerPassword) < 6 || strlen($registerPassword) > 12)     
                $errors['registerPassword'] = 'Your password must be between 6-12 characters.';

  2. #2
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    France, deep rural.
    17 Post(s)
    1 Thread(s)
    Why is that on fail, you populate both either a what seems to be a string variable $error and also an array $errors depending on the failure?

    Where do you echo out $error?

    Also, this looks very dubious to me:
    PHP Code:
    $_POST['registerSubmit'] == 'true' 
    When the form is submitted does it really have the string value 'true' or are you looking for a boolean true?

    When forking your code and things are not going as expected the very first thing you should do is var_dump() the values onto the screen somewhere, or into an error log file -- and then carefully inspect the values.

    in your case:
    PHP Code:
    // a line of debug
    var_dump$_POST ); 
    Then you should be inclined to use === to make sure those values match your expectations exactly (strict, value and type match), rather than relying on the woolly == (loose, value matches only).

    More here: PHP Truth table.


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts