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

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

    #61
    Sorry guys,
    but that is not the problem. I added the semi-colons and I am still 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 6

    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 6

    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 20

    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 24

    This is my code:
    [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]

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #62
      Originally posted by mideastgirl
      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 20
      mysql_query() returns false if there was an error, which then obviously is not a resource.

      remember: always test values that can have different data types and where the data type matters in the next usage.

      refer also to mysql_query().

      typical example (very basic):
      Code:
      $qry = mysql_query($sql) or die(mysql_error());

      Comment

      • Atli
        Recognized Expert Expert
        • Nov 2006
        • 5062

        #63
        Originally posted by mideastgirl
        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 6
        Since you now have ob_start() on your second line, before the include, it is clear that the output that is preventing you from setting the headers is being added before the <?php on line #1.

        There simply is no other explanation for this error. There is something being sent before the <?php on line #1. To fix this, you need to find out what it is and remove it.
        A white-space, some hidden unicode marker... something.

        P.S.
        SharePoint Designer... isn't that just FrontPage for Vista? Does it even support PHP? (Meaning, color highlighting, syntax error highlighter, and such.)

        In any case, if you are having a hard time finding the problem in that, try opening your file in Notepad++. It's very good at spotting trash characters and such.

        Comment

        • mideastgirl
          New Member
          • Jun 2009
          • 65

          #64
          Atli,
          I have opened the document in Notepad ++ and some of the characters are in color, like semi-colons and such. However I do not know how to identify which characters are trash. Are the one's in color trash? Not really sure. I am going to mess with it more and hopefully figure it out.

          Dormilich,
          Are you suggesting, as is the link you sent me, that I need to use mysql_query() to see if the resource (variable/password?) I am using is a variable at all? Little confused on what that means. I kind of gathered that I need to go into my database and ensure that the password is entered as VARCHAR as opposed to anything else???? Let me know if I am on the right track.

          Comment

          • Dormilich
            Recognized Expert Expert
            • Aug 2008
            • 8694

            #65
            Originally posted by mideastgirl
            Dormilich,
            Are you suggesting, as is the link you sent me, that I need to use mysql_query() to see if the resource (variable/password?) I am using is a variable at all?
            first, every variable in PHP conforms to a data type (this type is not necessarily always the same—PHP is a so-called dynamically typed lanuage [ref.]) (that's got nothing to do with password, etc.). further, every (strictly speaking) function in PHP returns a value (this can be any of the alredy mentioned data types or "void" (no return value)). since even we experts do not know this stuff from all the 2,000+ PHP function we can look them up in the manual, where in the beginning a description is given what variables you must provide (minimum parameter number along with their type) and what the function returns (in which case).

            example (how to read the manual*)

            Description
            Code:
            resource mysql_query ( string $query [, resource $link_identifier ] )
            mysql_query() sends a unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier .
            Parameters
            this means, you must provide a SQL sting as input and optionally the connection (resource) variable. you'll get a resultset (a resource type) return value (except otherwise stated in the "return values" section). optional parameters are set in square brackets ( [ ] )

            query

            A SQL query

            The query string should not end with a semicolon.
            link_identifier

            The MySQL connection. If the link identifier is not specified, the last link opened by mysql_connect() is assumed. If no such link is found, it will try to create one as if mysql_connect() was called with no arguments. If by chance no connection is found or established, an E_WARNING level error is generated.
            the description what each of the input parameters is.

            Return Values

            For SELECT, SHOW, DESCRIBE, EXPLAIN and other statements returning resultset, mysql_query() returns a resource on success, or FALSE on error.

            For other type of SQL statements, INSERT, UPDATE, DELETE, DROP, etc, mysql_query() returns TRUE on success or FALSE on error.

            The returned result resource should be passed to mysql_fetch_arr ay(), and other functions for dealing with result tables, to access the returned data.

            Use mysql_num_rows( ) to find out how many rows were returned for a SELECT statement or mysql_affected_ rows() to find out how many rows were affected by a DELETE, INSERT, REPLACE, or UPDATE statement.

            mysql_query() will also fail and return FALSE if the user does not have permission to access the table(s) referenced by the query.
            as you can see, the mysql_query() function usually returns a ressource type (variable). but when reading under "return values" you'll see that this is not the only option, mysql_query() in general returns FALSE if there was an error (that is common for many functions) and sometimes it may return TRUE (both are boolean data types. and if your next function expects a resource input data type, it won't let you away if you provide a boolean (or any other)

            * this is important as most errors can be explained at/tracked down to this level

            Code:
            var_dump($unknown_var);
            will show you the content AND data type of the variable of interest (this is one of the #1 debugging functions)

            you should also cross-read at wikipedia about programming languages, there are some basic termini (like "data type" or "return value") that make discussing bugs and programmes much easier.

            Comment

            • Atli
              Recognized Expert Expert
              • Nov 2006
              • 5062

              #66
              Originally posted by mideastgirl
              Atli,
              I have opened the document in Notepad ++ and some of the characters are in color, like semi-colons and such. However I do not know how to identify which characters are trash. Are the one's in color trash? Not really sure. I am going to mess with it more and hopefully figure it out.
              No, Notepad++ highlights the syntax in color so it is easier to read.

              Junk characters usually show up as black squares. They are hidden, so this is just how Notepad++ (and a lot of other editors) represent them.

              Pay close attention to the starting <?php tag. The rest isn't really important.
              There must be something before it. A space, a piece of HTML, a junk char... anything.

              If there is not, check the Format menu. If the Encode as UTF8 is selected, change it to the one above it: Encode as UTF8 without BOM.
              Normal UTF8 documents have leading identifier chars that cause the problem you are seeing.

              Comment

              • washington678
                New Member
                • Jul 2009
                • 1

                #67
                Thanks so much for sharing the post.


                <link removed: no unnecessary links, thanks>
                Last edited by Markus; Jul 13 '09, 07:21 PM. Reason: Removed link

                Comment

                • code green
                  Recognized Expert Top Contributor
                  • Mar 2007
                  • 1726

                  #68
                  ....Has she gone :- !

                  Comment

                  • hoopy
                    New Member
                    • Feb 2009
                    • 88

                    #69
                    I think she may have finally figured it out :D

                    Comment

                    Working...