Millar Posted April 25, 2006 Share Posted April 25, 2006 :'(, I have written a script, also I haven'e configured the MySQL to work yet so I know it wont. The problem I have is, on the area - var $name = $this->data(name); - I get a parse error, Parse error: parse error, unexpected T_VARIABLE. When I put that variable in quotes I get this error, Parse error: parse error, unexpected '\"'.Here is the code I'm using. <?//------------------------------------------------------// Require MySQL...//------------------------------------------------------require_once("MySQL.php");$sesID = $_COOKIE['xM_ID'];class user { function data ( $rowinfo ) { $rowinfo = "'$rowinfo'"; $query = "SELECT * FROM xM_members WHERE id = '$sesID'"; $result = mysql_query( $this->query ); $row = mysql_fetch_array( $this->result ); $return = "$row[$rowinfo]"; return $return; } //var $query = "SELECT * FROM xM_members WHERE id = "; //var $result = mysql_query( $this->query ); //var $row = mysql_fetch_array( $this->result ); var $name = "$this->data(name)";}$user = new user;print "Logged in as: $user->name";print "$sesID";?> Link to comment Share on other sites More sharing options...
justsomeguy Posted April 25, 2006 Share Posted April 25, 2006 Try putting name in quotes. You don't need all the quotes around everything else though. <?//------------------------------------------------------// Require MySQL...//------------------------------------------------------require_once("MySQL.php");$sesID = $_COOKIE['xM_ID'];class user {function data ( $rowinfo ) { $rowinfo = "'$rowinfo'"; $query = "SELECT * FROM xM_members WHERE id = '$sesID'"; $result = mysql_query( $this->query ); $row = mysql_fetch_array( $this->result ); $return = $row[$rowinfo]; return $return;} //var $query = "SELECT * FROM xM_members WHERE id = "; //var $result = mysql_query( $this->query ); //var $row = mysql_fetch_array( $this->result );var $name = $this->data("name");}$user = new user;print "Logged in as: {$user->name}";print $sesID;?> Link to comment Share on other sites More sharing options...
Millar Posted April 26, 2006 Author Share Posted April 26, 2006 Try putting name in quotes. You don't need all the quotes around everything else though.<?//------------------------------------------------------// Require MySQL...//------------------------------------------------------require_once("MySQL.php");$sesID = $_COOKIE['xM_ID'];class user {function data ( $rowinfo ) { $rowinfo = "'$rowinfo'"; $query = "SELECT * FROM xM_members WHERE id = '$sesID'"; $result = mysql_query( $this->query ); $row = mysql_fetch_array( $this->result ); $return = $row[$rowinfo]; return $return;} //var $query = "SELECT * FROM xM_members WHERE id = "; //var $result = mysql_query( $this->query ); //var $row = mysql_fetch_array( $this->result );var $name = $this->data("name");}$user = new user;print "Logged in as: {$user->name}";print $sesID;?> <{POST_SNAPBACK}> Didn't work :'(.... Link to comment Share on other sites More sharing options...
justsomeguy Posted April 26, 2006 Share Posted April 26, 2006 Well don't keep me in suspense, what happened? Any error messages? What did it do? Link to comment Share on other sites More sharing options...
Chocolate570 Posted April 26, 2006 Share Posted April 26, 2006 It gives the T_VARIABLE error on this line:var $name = $this->data("name");(we were discussing this on MSN ) Link to comment Share on other sites More sharing options...
justsomeguy Posted April 26, 2006 Share Posted April 26, 2006 I'm thinking it's because there is that line of executable code in the class definition. I believe that the class definition only declares everything, it declares functions (methods) and variables (properties). If you want to declare and initialize a variable, you can only initialize it to a constant value, not through a function call. If he wants something to execute when the class gets instantiated, then that should go in the constructor. class user { function user () { $this->name = $this->data("name"); } function data ( $rowinfo ) { $rowinfo = "'$rowinfo'"; $query = "SELECT * FROM xM_members WHERE id = '$sesID'"; $result = mysql_query( $this->query ); $row = mysql_fetch_array( $this->result ); return $row[$rowinfo]; }} Edit: I'm pretty sure you want to use mysql_fetch_assoc instead of mysql_fetch_array, $rowinfo is a string, not a number Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now