Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Parse error: syntax error, unexpected '{' in

    Hello!

    I am pretty new to PHP coding and have hit a stumbling block (by new I mean trial by fire).

    I have a login page which give me an error:
    Parse error: syntax error, unexpected '{' in index5.php on line 7

    I have checked and I have closed all of my {'s but still get the error. The chunk of code is below:

    PHP Code:
    if(isset($_POST['user'])
    {
        
    $user sanitizeString($_POST['user'])
        
    $pass sanitizeString($_POST['user'])
        if (
    $user == "" $pass == "")
        {
        
    $error "Not all fields were entered<br />"
        
    }
        else
        {
            
    $query "SELECT user,pass FROM users
                WHERE user='$user AND pass=$pass"
            
            
    if (mysql_num_rows(queryMysql($query)) == 0
            
    {
                
    $error "Username/Password Invalid<br />";
            }
            else
            {
                
    $_SESSION['user'] = $user;
                
    $_SESSION['pass'] = $pass;
                die(
    "You are now logged in.")
            }
        }

    Any ideas would really be appreciated. I have a feeling it is probably something simple and stupid, but I'll take the chance.
    Last edited by Inigoesdr; 02-01-2012 at 12:32 AM.

  • #2
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,269
    Thanks
    10
    Thanked 277 Times in 276 Posts
    You've missed the semicolons at the ends of several statements, like lines 3,4,7,12,22

    Dave

  • #3
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by tracknut View Post
    You've missed the semicolons at the ends of several statements, like lines 3,4,7,12,22

    Dave
    This. Just in case you don't understand, and end of line has to be defined in PHP using the ;. Otherwise, it just counts the next line as part of the same statement.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #4
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Tried it

    I fixed the semicolons (I caught that right after I posted). But still doesn't take care of the Parse error: syntax error, unexpected '{' errors. I counted and recounted and it seems that they match up perfectly. So far that seems to have worked on that error but now I am getting:

    Parse error: syntax error, unexpected T_STRING in index5.php on line 16

    PHP Code:
    if(isset($_POST['user']))
    {
        
    $user sanitizeString($POST['user']);
        
    $pass sanitizeString($POST['pass']);
        if (
    $user == "" $pass == "")
        {
            
    $error "Not all fields entered<br />;
        }
        else
        {
            $query = "
    SELECT userpass FROM users
                WHERE user
    ='$user' and pass='$pass'";
            
            if (mysql_num_rows(queryMysql($query)) == 0
            {
                $error = "
    Username/Password invalid<br />";
            }
            else
            {
                $_SESSION['user'] = $user;
                $_SESSION['pass'] = $pass;
                die("
    You are now logged in");
            }
        }

    Line 16 is the select statement: $query = "SELECT user, pass FROM users
    WHERE user='$user' and pass='$pass'";

    Like I said I am a fish out of water here, but trying to muddle my way through.

  • #5
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    You're missing a close quote now. Use an IDE that has a syntax check and you will spot syntax errors before you even load the file.

    Also, please remember to read the stickies for this forum. In particular the one about using [php][/php] tags when posting code.

  • #6
    Senior Coder
    Join Date
    Aug 2006
    Posts
    1,269
    Thanks
    10
    Thanked 277 Times in 276 Posts
    You're missing a quote at the end of:
    Code:
    $error = "Not all fields entered<br />";

  • #7
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by gsness View Post
    I fixed the semicolons (I caught that right after I posted). But still doesn't take care of the Parse error: syntax error, unexpected '{' errors. I counted and recounted and it seems that they match up perfectly. So far that seems to have worked on that error but now I am getting:

    Parse error: syntax error, unexpected T_STRING in index5.php on line 16

    PHP Code:
    if(isset($_POST['user']))
    {
        
    $user sanitizeString($POST['user']);
        
    $pass sanitizeString($POST['pass']);
        if (
    $user == "" $pass == "")
        {
            
    $error "Not all fields entered<br />;
        }
        else
        {
            $query = "
    SELECT userpass FROM users
                WHERE user
    ='$user' and pass='$pass'";
            
            if (mysql_num_rows(queryMysql($query)) == 0
            {
                $error = "
    Username/Password invalid<br />";
            }
            else
            {
                $_SESSION['user'] = $user;
                $_SESSION['pass'] = $pass;
                die("
    You are now logged in");
            }
        }

    Line 16 is the select statement: $query = "SELECT user, pass FROM users
    WHERE user='$user' and pass='$pass'";

    Like I said I am a fish out of water here, but trying to muddle my way through.
    You should learn more about the errors PHP gives you. It's saying that it didn't expect a string on line 16. This means that before or on line 16, you've missed something.

    With the PHP code highlighting on this forum, I'm sure you can notice your missing " . I would suggest using an IDE like Netbeans which will highlight and hint code for you.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.

  • #8
    New to the CF scene
    Join Date
    Jan 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I have the close code, but it is further down the script. I didn't include it because I thought it would be better to give the segment of script instead of the whole page.

    Here is the entire script:

    PHP Code:
    <?php //srlogin.php
    include_once 'srheader.php';
    echo 
    "<h3>User Log In</h3>";
    $error $user $pass "";

    if(isset(
    $_POST['user']))
    {
        
    $user sanitizeString($POST['user']);
        
    $pass sanitizeString($POST['pass']);
        if (
    $user == "" $pass == "")
        {
            
    $error "Not all fields entered<br />;
        }
        else
        {
            $query = "
    SELECT user,pass FROM users
                WHERE user
    ='$user' and pass='$pass'";
            
            if (mysql_num_rows(queryMysql($query)) == 0
            {
                $error = "
    Username/Password invalid<br />";
            }
            else
            {
                $_SESSION['user'] = $user;
                $_SESSION['pass'] = $pass;
                die("
    You are now logged in");
            }
        }
    }

    echo <<<_END

    <form method='post' action='srlogin.php'>$error
    Username <input type='text' maxlength='50' name='user'
        value='$user' /><br />
    Password <input type= 'password' maxlength='20' name='pass'
        value='$pass' /><br />
    &nbsp$ &nbsp$ &nbsp$ &nbsp$ &nbsp$ &nbsp$ &nbsp$ 
    <input type='submit' value='Login' />
    </form>
    _END;
    ?>
    Last edited by Inigoesdr; 02-01-2012 at 01:57 AM.

  • #9
    Senior Coder
    Join Date
    Jul 2011
    Posts
    1,226
    Thanks
    3
    Thanked 171 Times in 171 Posts
    Quote Originally Posted by gsness View Post
    I have the close code, but it is further down the script. I didn't include it because I thought it would be better to give the segment of script instead of the whole page.

    Here is the entire script:

    <?php //srlogin.php
    include_once 'srheader.php';
    echo "<h3>User Log In</h3>";
    $error = $user = $pass = "";

    if(isset($_POST['user']))
    {
    $user = sanitizeString($POST['user']);
    $pass = sanitizeString($POST['pass']);
    if ($user == "" | $pass == "")
    {
    $error = "Not all fields entered<br />;
    }
    else
    {
    $query = "SELECT user,pass FROM users
    WHERE user='$user' and pass='$pass'";

    if (mysql_num_rows(queryMysql($query)) == 0
    {
    $error = "Username/Password invalid<br />";
    }
    else
    {
    $_SESSION['user'] = $user;
    $_SESSION['pass'] = $pass;
    die("You are now logged in");
    }
    }
    }

    echo <<<_END

    <form method='post' action='srlogin.php'>$error
    Username <input type='text' maxlength='50' name='user'
    value='$user' /><br />
    Password <input type= 'password' maxlength='20' name='pass'
    value='$pass' /><br />
    &nbsp$ &nbsp$ &nbsp$ &nbsp$ &nbsp$ &nbsp$ &nbsp$
    <input type='submit' value='Login' />
    </form>
    _END;
    ?>
    We have answered you in our posts, and given you the solutions. Not only that, we have told you about techniques to help you in the future.

    Also, PLEASE pay attention to the forum stickies, AND MY SIGNATURE, about [PHP] tags.
    Useful function to retrieve difference in times
    The best PHP resource
    A good PHP FAQ
    PLEASE remember to wrap your code in [PHP] tags.
    PHP Code:
    // Replace this
    if(isset($_POST['submitButton']))
    // With this
    if(!empty($_POST))
    // Then check for values/forms. Some IE versions don't send the submit button 
    Always code as if the guy who ends up maintaining your code will be a violent psychopath who knows where you live.


  •  

    Posting Permissions

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