Parse error: syntax error, unexpected $end in...

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • mideastgirl
    New Member
    • Jun 2009
    • 65

    #31
    I removed the print_r codes and the header comments, and now am back to getting the unexpected $end error again. I am absolutely flustered with this scripting.
    This is what I have:

    [code=php]
    <?php
    include("admin-dbcon.php");
    //sanitize the user input to ensure random usernames cannot be used
    $sUsername= mysql_real_esca pe_string($_POS T ['Username']);
    $sPassword = mysql_real_esca pe_string($_POS T['Password']);
    //ensure username and password are valide
    $sql ="SELECT * from admin_login WHERE $sUsername = 'username' AND $sPassword = 'password'";

    if ($validate = mysql_query($sq l))
    {

    $isvalide=mysql _num_rows($vali date);
    echo $isvalide;

    //if valid login send on, if not send to error page
    if ($isvalide)
    {
    $_SESSION['username'] = $_POST['username'];
    while ($row=mysql_fet ch_array($valid ate))
    {
    $_SESSION['userid']=$row["ID"];
    }
    {
    $_SESSION['username'] = $_POST['username'];
    while ($row=mysql_fet ch_array($valid ate))
    {
    $_SESSION['userid']=$row["ID"];
    }
    header("Locatio n: admintasks.php" );
    }
    header ("Location: login-error.php");
    ?>
    [/code]
    And this is the error I am getting:
    Parse error: syntax error, unexpected $end in /home/content/m/i/d/mideasthonors/html/adminloginproce ss.php on line 32

    When I deleted the echo statement as you suggested and the last curly bracket that went with it, it began to say this. So I replaced the curly bracket and I am still getting this error:(

    Comment

    • mideastgirl
      New Member
      • Jun 2009
      • 65

      #32
      I think I fixed it?!

      at the end of the code I placed }} one on line 32 and one on 33 and a blank page now comes up...BUT I need admintasks.php to come up instead of a blank page, with ...adminloginpr ocess.php as the website. Any suggestions?

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #33
        try putting an exit(); after each header() (no need to further execute the script when relocated)

        NOTE: proper indentation helps counting the brackets, see here (use the one you like best, but stick to the one you use)
        Last edited by Dormilich; Jun 30 '09, 02:03 PM. Reason: added indentation info

        Comment

        • mideastgirl
          New Member
          • Jun 2009
          • 65

          #34
          I tried adding the exits:

          [code=php]
          <?php
          include("admin-dbcon.php");
          //sanitize the user input to ensure random usernames cannot be used
          $sUsername= mysql_real_esca pe_string($_POS T ['Username']);
          $sPassword = mysql_real_esca pe_string($_POS T['Password']);
          //ensure username and password are valide
          $sql ="SELECT * from admin_login WHERE $sUsername = 'username' AND $sPassword = 'password'";

          if ($validate = mysql_query($sq l))
          {

          $isvalide=mysql _num_rows($vali date);
          echo $isvalide;

          //if valid login send on, if not send to error page
          if ($isvalide)
          {
          $_SESSION['username'] = $_POST['username'];
          while ($row=mysql_fet ch_array($valid ate))
          {
          $_SESSION['userid']=$row["ID"];
          }
          {
          $_SESSION['username'] = $_POST['username'];
          while ($row=mysql_fet ch_array($valid ate))
          {
          $_SESSION['userid']=$row["ID"];
          }
          header("Locatio n: admintasks.php" )exit();
          }
          header ("Location: login-error.php")exit ();
          }
          }
          ?>
          [/code]
          And am now receiving this error-Parse error: syntax error, unexpected T_EXIT in /home/content/m/i/d/mideasthonors/html/adminloginproce ss.php on line 29

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #35
            Originally posted by mideastgirl
            And am now receiving this error-Parse error: syntax error, unexpected T_EXIT in /home/content/m/i/d/mideasthonors/html/adminloginproce ss.php on line 29
            add a ; after the header() function calls.

            Comment

            • dlite922
              Recognized Expert Top Contributor
              • Dec 2007
              • 1586

              #36
              Do you look at the lines before you post the errors here?

              You won't learn much if we correct every semi-colon for you. Don't be scared of the code, it's not as complicated and mysterious as you make it seem. Have a little more confidence in yourself.



              Dan

              Comment

              • Dormilich
                Recognized Expert Expert
                • Aug 2008
                • 8694

                #37
                generally, if the error message says something about unexpected T_*** then you should look for missing parentheses, brackets, commas, semi-colons and the like.

                Comment

                • Atli
                  Recognized Expert Expert
                  • Nov 2006
                  • 5062

                  #38
                  Also, if you get a decent IDE, like Aptana, NetBeans or even Notepad++, they pretty much show you exactly where syntax errors like these are.

                  You should put a bit of time into learning the basic syntax before you try coding anything real. Will save you a LOT of time on errors like these.
                  Errors, like the last one you posted, should be obvious to you once you've gotten to know the basics.

                  Comment

                  • mideastgirl
                    New Member
                    • Jun 2009
                    • 65

                    #39
                    how do I go to the next page?

                    I removed the exits after the header functions, and there were semicolons already after the header functions, unless I needed to move them so that they were before the exit, in any case I removed the exits and now I am still unable to move onto the next page!!! I cannot figure this out!

                    Comment

                    • Dormilich
                      Recognized Expert Expert
                      • Aug 2008
                      • 8694

                      #40
                      give this "article" a read, it should clarify how to use the header() function.

                      Comment

                      • mideastgirl
                        New Member
                        • Jun 2009
                        • 65

                        #41
                        I read that article, and it said to do what I am already doing to get to the next "location". I also re-added the exists! The page is still not going to the next page. Should I have header at the top of the script? Instead of at the bottom?

                        Comment

                        • Atli
                          Recognized Expert Expert
                          • Nov 2006
                          • 5062

                          #42
                          There is still one major glitch in there.

                          First, take a look at the way you handle the execution of your SQL query.
                          You don't actually do anything if the SQL query were to fail. You simply let the code trail into nothingness.

                          When you execute a query, you typically check whether it is OK (as you do), but print an error message if it doesn't (which you do not).
                          [code=php]
                          $result = mysql_query($sq l);
                          if($result) {
                          // Do stuff with the result
                          }
                          else {
                          die("SQL Query failed!");
                          }[/code]

                          Second, take a look at the SQL query.
                          Typically, when you use SELECT to search for a value, you specify a column name and then provide a variable for the value that is to be checked.

                          Your code specifies a static value, but provides a variable for the column name.
                          It is supposed to be the other way around.

                          Combined, these two problems cause the code to completely ignore everything inside your first if statement, and since you don't provide anything as an alternative, it just gives you a blank page.

                          Comment

                          • mideastgirl
                            New Member
                            • Jun 2009
                            • 65

                            #43
                            what do you mean by static value?
                            Also can you please check to ensure I included your first prognosis correctly in my scripting:

                            [code=php]
                            <?php
                            include("admin-dbcon.php");
                            //sanitize the user input to ensure random usernames cannot be used
                            $sUsername= mysql_real_esca pe_string($_POS T ['Username']);
                            $sPassword = mysql_real_esca pe_string($_POS T['Password']);
                            //ensure username and password are valide
                            $sql ="SELECT * from admin_login WHERE $sUsername = 'username' AND $sPassword = 'password'";
                            if ($validate = mysql_query($sq l))
                            {
                            $isvalide=mysql _num_rows($vali date);
                            echo $isvalide;
                            }
                            else {
                            die (SQL Query failed!");

                            //if valid login send on, if not send to error page
                            if ($isvalide)
                            {
                            $_SESSION['username'] = $_POST['username'];
                            while ($row=mysql_fet ch_array($valid ate))
                            {
                            $_SESSION['userid']=$row["ID"];
                            }
                            {
                            $_SESSION['username'] = $_POST['username'];
                            while ($row=mysql_fet ch_array($valid ate))
                            {
                            $_SESSION['userid']=$row["ID"];
                            }
                            header("Locatio n: admintasks.php" );
                            exit;
                            }
                            header("Locatio n: login-error.php");
                            exit;

                            }
                            }
                            ?>
                            [/code]

                            Thank you

                            Comment

                            • Dormilich
                              Recognized Expert Expert
                              • Aug 2008
                              • 8694

                              #44
                              Originally posted by mideastgirl
                              what do you mean by static value?
                              er, exactly as in any dictionary described.

                              Originally posted by mideastgirl
                              Also can you please check to ensure I included your first prognosis correctly in my scripting:
                              nope, still the the same problem (about the "static" value)

                              Comment

                              • mideastgirl
                                New Member
                                • Jun 2009
                                • 65

                                #45
                                Is the static value you are referring to the 'username' and 'password'??? If that is what you are referring to that is what my columns are on my SQL Table so I am not sure how that is static??? Unless I need to actually enter in the passwords or username on the page and that does not seem right at all.

                                Comment

                                Working...