SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)

    please, Parse error: syntax error, unexpected T_ELSE (can you spot it)

    PHP Code:
    <?php
    echo "<h1>Register</h1>";

    $submit $_POST['submit'];
    //form data
    $fullname strip_tags($_POST['fullname']);
    $username strip_tags($_POST['username']);
    $password strip_tags($_POST['password']);
    $repeatpassword strip_tags($_POST['repeatpassword']);
    $date date("Y-m-d");

    if (
    $submit)
    {
    //check for registration form details
        
    if ($fullname&&$username&&$password&&$repeatpassword)
    {
    //encript password
    $password md5($password);
    $repeatpassword md5($repeatpassword);
    if (
    $password==$repeatpassword)
    {
    //check char lenght of username and fullname
    if (strlen($username)>25||strlen($fullname)>25)
    {
    echo 
    "Lenght of username or fullname is too long";
    }
    else
    {
    //check password length
    if(strlen($password)>25||strlen($password)<6)
    {
    echo
    "Password must be between 6 and 25 characters";
    }
    }else
    {
    //register the user!

    echo "Success!!";
    }
    }
    else
        echo
    "Your passwords do not match!";

    }
    else
            echo 
    "Please fill in <b>all</> fields!";

    }
    ?>

  2. #2
    From Italy with love silver trophybronze trophy
    guido2004's Avatar
    Join Date
    Sep 2004
    Posts
    9,508
    Mentioned
    163 Post(s)
    Tagged
    4 Thread(s)
    That's why proper indentation is important.
    PHP Code:
    <?php
    echo "<h1>Register</h1>";

    $submit $_POST['submit'];
    //form data
    $fullname strip_tags($_POST['fullname']);
    $username strip_tags($_POST['username']);
    $password strip_tags($_POST['password']);
    $repeatpassword strip_tags($_POST['repeatpassword']);
    $date date("Y-m-d");

    if (
    $submit)
    {
      
    //check for registration form details
      
    if ($fullname&&$username&&$password&&$repeatpassword)
      {
        
    //encript password
        
    $password md5($password);
        
    $repeatpassword md5($repeatpassword);
        if (
    $password==$repeatpassword)
        {
          
    //check char lenght of username and fullname
          
    if (strlen($username)>25||strlen($fullname)>25)
          {
            echo 
    "Lenght of username or fullname is too long";
          }
          else
          {
            
    //check password length
            
    if(strlen($password)>25||strlen($password)<6)
            {
              echo
    "Password must be between 6 and 25 characters";
            }
          }
          else         
    // <---- this else is giving the error (you can't have if ... else ... else ...)
          
    {
            
    //register the user!
            
    echo "Success!!";
          }
        }
        else echo
    "Your passwords do not match!";
      }
      else echo 
    "Please fill in <b>all</> fields!";
    }
    ?>

  3. #3
    SitePoint Addict
    Join Date
    Oct 2010
    Posts
    323
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    thanks, guido, please could you give a link to ow the if ...else...else.. should be structtured properly


Bookmarks

Posting Permissions

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