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

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hoopy
    New Member
    • Feb 2009
    • 88

    #46
    This looks like a real hair pulling time thread.

    You have your variables in the wrong place:

    Code:
    $sql ="SELECT * from admin_login WHERE $sUsername = 'username' AND $sPassword = 'password'";
    So if someone entered the username Fred and password of test the SQL which would be executed would be:

    SELECT * from admin_login WHERE Fred = 'username' AND test = 'password'

    It should be:

    Code:
    $sql ="SELECT * from admin_login WHERE username = '$sUsername' AND password = '$sPassword'";
    mideastgirl, it seems you should concentrate on learning how to debug code but putting in markers, etc so you can see where things are failing and narrow down the problem.

    Comment

    • mideastgirl
      New Member
      • Jun 2009
      • 65

      #47
      I have tried adding what Atli has told me to use which would help me identify my problems but I work for a University and there is no funding available to purchase these editors.
      Thank you very much for spelling out my problem to me! Believe me it is quite frustrating when I have to dance around the problem. Once I understand where I screwed up, instead of guessing, its much easier for me to move on with the next problem and the next page that I must go onto to put this website to rest.

      I thought that is what the others were suggesting, that is with the 'username' but when Atli initially informed me to us the sanitize string with the $sUsername, it would have been a bit more helpful if the problem would have been brought to my attention when I was working on that portion, so as not to have me guess where these static variables are.

      On a separate note: I have changed the variables and I am assuming I can remove the 14th line, which I am now receiving an error for?? Which validates the username and password. But if they are being validated in the line I just fixed, I do not see why they would need to be validated again.

      Comment

      • mideastgirl
        New Member
        • Jun 2009
        • 65

        #48
        Scratch my last comment. I removed it and now my page just keeps going to a blank page! Grrrrr! This is a hair pulling problem!

        Comment

        • hoopy
          New Member
          • Feb 2009
          • 88

          #49
          Seems like you are going about in quite a long way. This is a simplified version of your code:

          Code:
          <?php
          include("admin-dbcon.php");
          
          // you need this to be able to use sessions
          session_start();
          
          //sanitize the user input to ensure random usernames cannot be used
          $sUsername= mysql_real_escape_string($_POST['Username']);
          $sPassword = mysql_real_escape_string($_POST['Password']);
          
          //ensure username and password are valide
          $qry = mysql_query(" 
            SELECT * from admin_login 
            WHERE = username '$sUsername' 
            AND password = '$sPassword' 
          ");
          
          // check the number of rows returned 
          if(mysql_num_rows($qry) == 0)
          {
            // not a valid login redirect to fail 
            header("Location: login-error.php");
            exit;
          }
          
          // if you get here then you have made a match 
          // store data in session variables 
          $row = mysql_fetch_array($qry);
          $_SESSION['username'] = $row['username'];
          $_SESSION['userid'] = $row['ID'];
          
          // redirect user onto admintasks.php
          header("Location: admintasks.php");
          ?>
          This is untested but it does what you need it to do.

          Comment

          • mideastgirl
            New Member
            • Jun 2009
            • 65

            #50
            I do appreciate the help hoopy! However I am getting this error:

            Warning: session_start() [function.sessio n-start]: Cannot send session cookie - headers already sent by (output started at /home/content/m/i/d/mideasthonors/html/adminloginproce ss.php:1) in /home/content/m/i/d/mideasthonors/html/adminloginproce ss.php on line 5

            Warning: session_start() [function.sessio n-start]: Cannot send session cache limiter - headers already sent (output started at /home/content/m/i/d/mideasthonors/html/adminloginproce ss.php:1) in /home/content/m/i/d/mideasthonors/html/adminloginproce ss.php on line 5

            Warning: mysql_num_rows( ): supplied argument is not a valid MySQL result resource in /home/content/m/i/d/mideasthonors/html/adminloginproce ss.php on line 19

            Warning: Cannot modify header information - headers already sent by (output started at /home/content/m/i/d/mideasthonors/html/adminloginproce ss.php:1) in /home/content/m/i/d/mideasthonors/html/adminloginproce ss.php on line 22

            Which seems to be the header problem again:(

            Comment

            • hoopy
              New Member
              • Feb 2009
              • 88

              #51
              There must be some trailing spaces or output before. Make sure you dont have a blank line at the top ie:

              Code:
              <?php
              echo ("hi");
              ?>
              It has to be:

              Code:
              <?php
              echo ("hi");
              ?>
              You cannot have any spaces or any output before you use a header() call.

              Please paste the entire contents of your code. ALso admin-dbcon.php but remove any sensitive information like passwords, etc.

              Comment

              • hoopy
                New Member
                • Feb 2009
                • 88

                #52
                In fact attach the files so we can see where the output is being generated.

                Comment

                • mideastgirl
                  New Member
                  • Jun 2009
                  • 65

                  #53
                  Code from adminloginproce ss.php:
                  [code=php]
                  <?php
                  include("admin-dbcon.php");

                  // you need this to be able to use sessions
                  session_start() ;

                  //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
                  $qry = mysql_query("
                  SELECT * from admin_login
                  WHERE = username = '$sUsername'
                  AND password = '$sPassword'
                  ");

                  // check the number of rows returned
                  if(mysql_num_ro ws($qry) == 1)
                  {
                  // not a valid login redirect to fail
                  header("Locatio n: login-error.php");
                  exit;
                  }

                  // if you get here then you have made a match
                  // store data in session variables
                  $row = mysql_fetch_arr ay($qry);
                  $_SESSION['username'] = $row['username'];
                  $_SESSION['userid'] = $row['ID'];

                  // redirect user onto admintasks.php
                  header("Locatio n: admintasks.php" );
                  ?>
                  [/code]
                  **No spaces are shown

                  admin-dbcon.php:
                  [code=php]
                  <?php
                  $dbHost = 'mideasthonors. db.4381361.host edresource.com' ;
                  $dbName = 'xxx';
                  $dbUser = 'xxx;
                  $dbPass = 'xxx';

                  mysql_connect(" $dbHost","$dbUs er","$dbPass" ) or die("Error: Unable to connect to database! Please try again later.");

                  //Select the database we want to use
                  mysql_select_db ($dbName) or die("Error: Could not select database");
                  ?>
                  [/code]

                  Comment

                  • dlite922
                    Recognized Expert Top Contributor
                    • Dec 2007
                    • 1586

                    #54
                    make sure that "admin-dbcon.php" does not have any echo or print statements in it. Then delete the closing php bracket (the ?> at the bottom.

                    if this file does need to output something, then session_start() should come before that include line.




                    Dan

                    Comment

                    • hoopy
                      New Member
                      • Feb 2009
                      • 88

                      #55
                      Make sure there are no spaces at the bottom. Seems like you have an extra line underneath where you close PHP ie. ?> on both scripts.

                      Comment

                      • Atli
                        Recognized Expert Expert
                        • Nov 2006
                        • 5062

                        #56
                        If you can't spot where the output is being sent, try adding ob_start() at the very top of your script (before any includes), and ob_end_flush() at the very bottom (or at least after you header calls).

                        Those should buffer any output until you are ready to send it.
                        You can use them to narrow down exactly where the problem is.

                        Comment

                        • mideastgirl
                          New Member
                          • Jun 2009
                          • 65

                          #57
                          Thank you all for your suggestions. I have applied all of them and here is my code for adminloginproce ss.php:
                          [code=php]
                          <?php
                          ob_start()
                          include("admin-dbcon.php");

                          // you need this to be able to use sessions
                          session_start() ;

                          //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
                          $qry = mysql_query("
                          SELECT * from admin_login
                          WHERE = username = '$sUsername'
                          AND password = '$sPassword'
                          ");

                          // check the number of rows returned
                          if(mysql_num_ro ws($qry) == 0)
                          {

                          // not a valid login redirect to fail
                          header("Locatio n: login-error.php");
                          exit;
                          }

                          // if you get here then you have made a match
                          // store data in session variables
                          $row = mysql_fetch_arr ay($qry);
                          $_SESSION['username'] = $row['username'];
                          $_SESSION['userid'] = $row['ID'];
                          // redirect user onto admintasks.php
                          header("Locatio n: admintasks.php" );
                          ob_end_flush()
                          ?>
                          [/code]
                          And my code for admin-db.com.php:
                          [code=php]
                          <?php
                          $dbHost = 'mideasthonors. db.4381361.host edresource.com' ;
                          $dbName = 'xxx';
                          $dbUser = 'xxx';
                          $dbPass = 'xxx';

                          mysql_connect(" $dbHost","$dbUs er","$dbPass" ) or die("Error: Unable to connect to database! Please try again later.");

                          //Select the database we want to use
                          mysql_select_db ($dbName) or die("Error: Could not select database");
                          [/code]

                          ***Although it appears on here that I have spaces after my last line...it is not true. My ?> on adminloginproce ss.php is the very LAST line of my scripting, no other lines appear after it. I am using SharePoint Designer, not sure if that has anything to do with it.
                          After all of the suggestions from yesterday this is now the error I am receiving:
                          Parse error: syntax error, unexpected T_INCLUDE in /home/content/m/i/d/mideasthonors/html/adminloginproce ss.php on line 3
                          which has to do with the db-con.php file. However one can see that the db-con.php file has been set up properly, except that I deleted the ?> as suggested by one of you yesterday. I am assuming that if I replaced that I would still be taken to a blank page. I am not really sure what steps to follow next:(

                          Comment

                          • Dormilich
                            Recognized Expert Expert
                            • Aug 2008
                            • 8694

                            #58
                            Originally posted by mideastgirl
                            After all of the suggestions from yesterday this is now the error I am receiving:
                            Parse error: syntax error, unexpected T_INCLUDE in /home/content/m/i/d/mideasthonors/html/adminloginproce ss.php on line 3
                            I remember vaguely saying something about unexpected T_*** errors...
                            Originally posted by Dormilich
                            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

                            • hoopy
                              New Member
                              • Feb 2009
                              • 88

                              #59
                              Your missing semi-colons after:

                              ob_start() and ob_end_flush()

                              Make sure they are:

                              Code:
                              ob_end_flush(); and ob_start();

                              Comment

                              • Dormilich
                                Recognized Expert Expert
                                • Aug 2008
                                • 8694

                                #60
                                @hoopy: cheater ;)

                                .......

                                Comment

                                Working...