Parse error: syntax error, unexpected T_IF
Results 1 to 9 of 9

Thread: Parse error: syntax error, unexpected T_IF

  1. #1
    Junior Member
    Join Date
    Jun 2013
    Posts
    5

    Parse error: syntax error, unexpected T_IF

    I've just started coding PHP and i've stumbled on a little problem.
    I'm currently just coding a simple website Register/Login project. And i'm currently on to making a "Contact us" sub.

    So heres the code, if anyone could help me whats wrong:
    PHP Code:
    <?php
        
    if (empty($name) === true || empty($email) === true || empty($message) === true)  {
           
    $errors[] = 'Name, email and message are required!';
        } else {
        }
        
    // The else above is actually not needed thus you could remove it.  
        
    if (filter_var($emailFILTER_VALIDATE_EMAIL) === false) {
            
    $errors[] = 'That\'s not a valid email adress you have entered.';
        }    
        
        }    
        if (
    ctype_alpha($name) === false)  {
            
    $errors[] = 'Name must only contain letters!'
        
    if (empty($errors) === true);
       }
    ?>

  2. #2
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,428
    Are you sure you pasted the exact code? The error I get is:
    Parse error: syntax error, unexpected '}' in test.php on line 11
    since the '}' closing brace on line 11 has no matching '{' opening brace.

    Next problem I see is that the assignment statement on line 13 is never terminated (it's missing a semicolon at the end).

  3. #3
    Junior Member
    Join Date
    Jun 2013
    Posts
    5
    This is the exact error I get:
    Parse error: syntax error, unexpected T_IF in D:\xampp3\xampp\htdocs\contact.php on line 24
    I'm gonna try ending it and see if it's gonna lead me somewhere.

  4. #4
    Junior Member
    Join Date
    Jun 2013
    Posts
    5
    Didn't help, sadly.
    If anyone who maybe could contribute please post! Would be grateful

  5. #5
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,428
    You'll have to show us the actual code if you want us to help with the actual problem.

  6. #6
    Junior Member
    Join Date
    Jun 2013
    Posts
    5
    Ahh! Sorry :/
    PHP Code:
    <?php
    include 'core/init.php';
    include 
    'includes/overall/header.php';
    if (empty(
    $_POST) === false) {
       
    $errors = array();

        
    $name     $_POST ['name'];
        
    $email    $_POST ['email'];
        
    $message  $_POST ['message'];
    ?>
    <?php
        
    if (empty($name) === true || empty($email) === true || empty($message) === true)  {
           
    $errors[] = 'Name, email and message are required!';
        } else {
        }
        
    // The else above is actually not needed thus you could remove it.  
        
    if (filter_var($emailFILTER_VALIDATE_EMAIL) === false) {
            
    $errors[] = 'That\'s not a valid email adress you have entered.';
        }    
        
        }    
        if (
    ctype_alpha($name) === false);  {
            
    $errors[] = 'Name must only contain letters!'
        
    if (empty($errors) === true);}
       }
    ?>
    <h1>Contact</h1>
    <p>Below this, you can contact the webmaster of this website.<br>
    If you have any questions, or you've found any bugs with the site feel free to contact me.<br>
    <i>Note: Answers usually take place every 24 hours, or when webmaster's computer is turned on.</p>
    <form action="" method="post">
         <p>
        <?php
        
    if (empty($errors) === false)      {
            echo 
    '<ul>';
            foreach(
    $errors as $error)  {
               echo 
    '<li>'$error'</li>';
            }
            echo 
    '</u>';
        }
        
    ?> 
            <label for="name">Name:</label><br>
            <input type="text" name="name" id="name">
         </p>

         <p>
           <label for="email">Email:</label><br>
            <input type="text" name="email" id="email">
         </p>
         <p>
          <label for "message">Message:</label><br>
          <textarea name="message" id="message"></textarea>
         </p>
         <p>
            <input type="submit" value="Submit">
            </p>     
    <?php include 'includes/overall/footer.php'?>

  7. #7
    Pna lbh ernq guvf¿
    Join Date
    Jul 2004
    Location
    Kansas City area
    Posts
    19,428
    You still have the same issue on line 23 - the assignment statement is missing a terminating semicolon.

    In addition, the closing '}' brace on line 25 has no matching opening '{' brace. Considering that the if() statement on line 24 does absolutely nothing, I'm wondering if both it and the '}' brace on that line should be removed.

    EDIT: Also note that your check for the name containing only letters is outside of the if() statement on line 4. In other words, you'll be checking the contents of $name even in cases where you haven't even defined that variable.

  8. #8
    Junior Member
    Join Date
    Jun 2013
    Posts
    5
    I might be a dummy now. But how do I fix it if you would share?
    I get this error now, or not even an error a notice. But actully that's the only thing I need I think:
    Notice: Undefined variable: name in D:\xampp3\xampp\htdocs\contact.php on line 20

  9. #9
    Senior Member
    Join Date
    May 2013
    Location
    NYS
    Posts
    128
    Quote Originally Posted by Infected View Post
    I might be a dummy now. But how do I fix it if you would share?
    I get this error now, or not even an error a notice. But actully that's the only thing I need I think:
    That simply means the "name" variable doesn't exist, and/or neither does $name. You have to make the variable assignment.
    Or, maybe they exist, but not until AFTER you tried to use them. Sequencing matters.

    Rivet`

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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