Parse error: syntax error, unexpected T_VARIABLE

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Padfoot153
    New Member
    • Jan 2010
    • 4

    Parse error: syntax error, unexpected T_VARIABLE

    Hey, I'm getting the error:

    Parse error: syntax error, unexpected T_VARIABLE in /Users/Oscar/AwesomeSongz/userCake/profile.php on line 7

    with this code

    Code:
    <?php
    	require_once("models/config.php");
    	 
    	function signinTimeStamp()
    	{
    		
    		$sql = "SELECT LastSignIn FROM ".$db_table_prefix."Users WHERE User_ID = '"$user"'";
    		$result = $db->sql_query($sql);
    		$row = $db->sql_fetchrow($result);
    		
    		return ($row['LastSignIn']);
    	}
    	
    	function signupTimeStamp()
    	{
    		
    		$sql = "SELECT SignUpDate FROM ".$db_table_prefix."Users WHERE User_ID = '"$user"'";
    		$result = $db->sql_query($sql);
    		$row = $db->sql_fetchrow($result);
    		
    		return ($row['SignUpDate']);
    	}
    	
    	function groupID()
    	{
    		
    		$sql = "SELECT ".$db_table_prefix."Users.Group_ID, ".$db_table_prefix."Groups.* FROM ".$db_table_prefix."Users INNER JOIN ".$db_table_prefix."Groups ON ".$db_table_prefix."Users.Group_ID = ".$db_table_prefix."Groups.Group_ID WHERE User_ID  = '". $user ."'";
    		$result = $db->sql_query($sql);
    		$row = $db->sql_fetchrow($result);
    		$db->sql_freeresult($result);
    
    		return($row);
    	} 
    	
    	$user = $_GET["user"]; 	
    	
    	//Prevent the user visiting the logged in page if he/she is not logged in
    	if(!isUserLoggedIn()) { header("Location: login.php"); die; }
    	
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Welcome <?php echo $loggedInUser->display_username; ?></title>
    <link href="cakestyle.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <div id="wrapper">
    <div id="logo"></div>
    
    <!--
    
    	This is an simple profile page. You can easily get access to
        user properties via $loggedInUser variable which is globally accessible.
    
    -->
        <div id="regbox">
            
            <?php if(usernameExists($_GET["user"])) {?>
            <div style="text-align:center; padding-top:15px;">
            
            	Welcome to <strong><?php echo $user ?>'s</strong> profile.</p>
            	
                
                <p><?php echo $user ?> is a <strong><?php  $group = $loggedInUser->groupID(); echo $group['Group_Name']; ?></strong></p>
              
                
                <p><?php echo $user ?> joined on <?php echo date("l \\t\h\e jS Y",$loggedInUser->signupTimeStamp()); ?> </p>
                <p><?php echo $user ?> last logged in on <?php echo date("l \\t\h\e jS Y",$loggedInUser->signinTimeStamp()); ?> </p>
                
            </div>
            <?php
            } else {
            
            echo "This is not a valid username, <strong> " .$loggedInUser->display_username. " </strong></p>";
            
            }
            ?>
            
            
            
            
        </div>
    
    </div>
    </body>
    </html>
    <?php include("models/clean_up.php"); ?>
    Last edited by Dormilich; Jan 13 '10, 06:56 AM. Reason: corrected line number
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    which is line 13?

    Comment

    • Padfoot153
      New Member
      • Jan 2010
      • 4

      #3
      Sorry, Typed it wrong, should have been line 7

      Comment

      • dgreenhouse
        Recognized Expert Contributor
        • May 2008
        • 250

        #4
        You most probably have an open parenthesis somewhere.
        Like:
        if $success) { // missing start paren
        // do something
        }

        Basically, the PHP interpreter has found a variable reference when it was most likely (as mentioned) expecting a parenthesis .

        Look in /profile.php which it doesn't appear you've posted above.

        see: http://www.php.net/tokens for a explanation of PHP's tokens and other stuff.

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          there are the concatenation operators missing around $user.

          Comment

          • Padfoot153
            New Member
            • Jan 2010
            • 4

            #6
            What line is the $user on?

            Comment

            • Dormilich
              Recognized Expert Expert
              • Aug 2008
              • 8694

              #7
              this one:
              Sorry, Typed it wrong, should have been line 7

              Comment

              • Padfoot153
                New Member
                • Jan 2010
                • 4

                #8
                Yes, Fixed it , Thanks !

                Comment

                • dgreenhouse
                  Recognized Expert Contributor
                  • May 2008
                  • 250

                  #9
                  Line 7 should be:
                  Code:
                  $sql = "SELECT LastSignIn FROM ".$db_table_prefix."Users WHERE User_ID = '$user'";
                  
                  Are you sure User_ID is a string?
                  
                  If it's an integer, then the line should probably be:
                  $sql = "SELECT LastSignIn FROM ".$db_table_prefix."Users WHERE User_ID = $user";
                  
                  As a matter of fact, you can just eliminate the concatenation all together.
                  i.e.
                  $sql = "SELECT LastSignIn FROM $db_table_prefix Users WHERE User_ID = '$user'";
                  - or if integer -
                  $sql = "SELECT LastSignIn FROM $db_table_prefix Users WHERE User_ID = $user";
                  
                  -also-
                  $sql = sprintf("SELECT LastSignIn FROM $db_table_prefix Users WHERE User_ID = '%s'",$user);
                  -or if intger -
                  $sql = sprintf("SELECT LastSignIn FROM $db_table_prefix Users WHERE User_ID = %d",$user);

                  Comment

                  • dgreenhouse
                    Recognized Expert Contributor
                    • May 2008
                    • 250

                    #10
                    Didn't catch the db concatenation chars...

                    Good catch Dormilich...

                    Comment

                    • Dormilich
                      Recognized Expert Expert
                      • Aug 2008
                      • 8694

                      #11
                      well, that is the standard error (besides missing semi-colon) I make when it comes to this error message.

                      Comment

                      • dgreenhouse
                        Recognized Expert Contributor
                        • May 2008
                        • 250

                        #12
                        I make it all the time! :-)

                        In reference to the other thread, I've been poking into PHP's source - it's very heady! Whew!

                        But I think it's well worth the effort to know definitively what PHP is doing under the covers when it comes to database interactions. I've been meaning to build some extensions for some time... I think you've given me the impetus to go for it!

                        Enough to blur your eyesight!

                        :-)

                        Comment

                        • Dormilich
                          Recognized Expert Expert
                          • Aug 2008
                          • 8694

                          #13
                          spotting the error was additionally eased by Atli’s code highligther script (it’s not perfect, but good enough)

                          Comment

                          • dgreenhouse
                            Recognized Expert Contributor
                            • May 2008
                            • 250

                            #14
                            Originally posted by Dormilich
                            spotting the error was additionally eased by Atli’s code highligther script (it’s not perfect, but good enough)
                            Which highlighter script are you referring to? Me likes I'm sure...

                            Comment

                            • Markus
                              Recognized Expert Expert
                              • Jun 2007
                              • 6092

                              #15
                              This one. It's a little buggy but works well enough. Leave your thoughts on it in the feeback forum (the PHP syntax thread).

                              Comment

                              Working...