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 6 of 6
  1. #1
    Regular Coder
    Join Date
    Oct 2010
    Posts
    128
    Thanks
    26
    Thanked 0 Times in 0 Posts

    Verifying user error

    OK, I'm taking a PHP/MYSQL Class and am working on project. For this project, we're suppose to create a user login page along with admin pages. Well, I'm following along in the book and typed it line by line, well, the page that verify's the user information keeps saying there's an error. Thinking mistyped, I literally copied and pasted the code. I'm still getting the error.



    Here's the error: "Parse error: syntax error, unexpected '{' on line 8". NOTE: This is a beginners class. So, in my opinion, the code below probably isn't the best or the most secure way to do this. However, for this class, we are supposed to do it like the book. Thanks.

    PHP Code:
    <?php
    session_start
    ();
    // User is logging in
    if (isset($_POST["login"])){
    if (isset(
    $_POST["username"]) && ($_POST["username"]
    == 
    "phpbee")
    && isset(
    $_POST["password"]) && ($_POST["password"]
    == 
    "phpbee"){
    $_SESSION["Authenticated"] = 1;
    }
    else{
    $_SESSION["Authenticated"] = 0;
    }
    session_write_close();
    header("Location: protected.php");
    }
    // User is logging out
    if (isset($_GET["logout"])){
    session_destroy();
    header("Location: login.html");

  • #2
    Regular Coder
    Join Date
    Sep 2009
    Location
    Calgary, Alberta
    Posts
    243
    Thanks
    51
    Thanked 3 Times in 3 Posts
    Quote Originally Posted by javanewbie7 View Post
    OK, I'm taking a PHP/MYSQL Class and am working on project. For this project, we're suppose to create a user login page along with admin pages. Well, I'm following along in the book and typed it line by line, well, the page that verify's the user information keeps saying there's an error. Thinking mistyped, I literally copied and pasted the code. I'm still getting the error.



    Here's the error: "Parse error: syntax error, unexpected '{' on line 8". NOTE: This is a beginners class. So, in my opinion, the code below probably isn't the best or the most secure way to do this. However, for this class, we are supposed to do it like the book. Thanks.

    PHP Code:
    <?php
    session_start
    ();
    // User is logging in
    if (isset($_POST["login"])){
    if (isset(
    $_POST["username"]) && ($_POST["username"]
    == 
    "phpbee")
    && isset(
    $_POST["password"]) && ($_POST["password"]
    == 
    "phpbee"){
    $_SESSION["Authenticated"] = 1;
    }
    else{
    $_SESSION["Authenticated"] = 0;
    }
    session_write_close();
    header("Location: protected.php");
    }
    // User is logging out
    if (isset($_GET["logout"])){
    session_destroy();
    header("Location: login.html");
    You are missing a bracket at the end of this: this is how is should be
    PHP Code:
    if (isset($_POST["username"]) && ($_POST["username"
    == 
    "phpbee")) 
    and this is what you have:
    PHP Code:
    if (isset($_POST["username"]) && ($_POST["username"
    == 
    "phpbee"
    Thanks, Slayer

  • Users who have thanked SlayerACC for this post:

    javanewbie7 (04-27-2012)

  • #3
    Regular Coder
    Join Date
    Oct 2010
    Posts
    128
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Thanks.

    Now it's saying "
    Parse error: syntax error, unexpected T_BOOLEAN_AND on line 9

    I've googled and noticed that it could too many parentheses. I went through the code and it seems to match up. COuld it be something else?

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by javanewbie7 View Post
    Thanks.

    Now it's saying "
    Parse error: syntax error, unexpected T_BOOLEAN_AND on line 9

    I've googled and noticed that it could too many parentheses. I went through the code and it seems to match up. COuld it be something else?
    Post your entire updated code. You have an if() condition at the end of your original post that cuts off, but your error is before that.

  • #5
    Regular Coder
    Join Date
    Oct 2010
    Posts
    128
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Below is the full code for the auth.php page (updated with the first person's suggestions). We were told to go by what's in the book, problem is, there isn't anything after the if statement. I even went to the book's website to dl the source code from the book and it's the same as it is below.


    PHP Code:
    ##### begin #####
    ##### auth.php #####
    <?php

      session_start
    ();
     
    // User is logging in
      
    if (isset($_POST["login"])){
     if (isset(
    $_POST["username"]) && ($_POST["username"]  
    == 
    "phpbee"))  && isset($_POST["password"]) 
       && (
    $_POST["password"]
        == 
    "phpbee"){
          
    $_SESSION["Authenticated"] = 1;
      }
      else{
         
    $_SESSION["Authenticated"] = 0;
      }
      
    session_write_close();
      
    header("Location: protected.php");
      }
      
    // User is logging out
      
    if (isset($_GET["logout"])){
         
    session_destroy();
         
    header("Location: login.html");
      }

    ?>
    ##### auth.php #####
    ##### end ####

  • #6
    Regular Coder
    Join Date
    Oct 2010
    Posts
    128
    Thanks
    26
    Thanked 0 Times in 0 Posts
    Nevermind. I figured it out. That to everyone who helped.


  •  

    Posting Permissions

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