jkewlo Posted October 25, 2009 Share Posted October 25, 2009 Hell, I am receiving the following errors in one of my class's Parse error: syntax error, unexpected '(', expecting '{' in /var/www/www.eve-lounge.com/htdocs/includes/data/user.class.php on line 10 is the error and this is my whole code for user.class.php, I cant seem to figure out why I am receiving the errors <?php ###################### # MoJo Social Engine # # Function.class.php # ###################### session_start(); require_once('config.php'); require_once('database.php'); class user() { public $username; public $password; public $vpassword; public $email; public $ip; public $fname; public $lname; public $age; public $id; private $_db; static private $_instance = null; private function __construct() { session_start(); } static public function getInstance() { if (self::$_instance == null) { self::$_instance = new Login(); } return self::$_instance; } function register($username, $password, $email, $ip, $fname, $lname, $age) { if($action == "register") { $db = new Database(); if(!$username || !$password || !$vpassword || !$email || !$fname || !$lname || !$age) { $_SESSION['error'] = "One or more of the fields was left empty, Please fill all fields out! Thanks o.O"; } // END // IF USERNAME IS TAKEN $sql = "SELECT username FROM users WHERE username=$username"; if($sql > 0) { return "ERROR_Username"; } // END // IF $password matches $vpassword if($password != $vpassword) { return "ERROR_Password"; } // END if($email == "") { return "ERROR_Email"; } // END if($fname == "") { return "ERROR_First_Name"; } // END if($lname == "") { return "ERROR_Last_Name"; } // END if($age == "") { return "ERROR_Age"; } // END } } // END function Login($username, $password) { $db = new Database(); $sql = "SELECT * FROM users WHERE username=$username AND password=$password"; $db->query($sql); $date = date("Y-m-d H:i:s", time()); $sql1="UPDATE users SET online=1 WHERE username='". $username ."'"; $db->query($sql1); if($db->nextRecord()){ $_SESSION['status'] = 'logged'; // SESSION FOR USER BEING LOGGED! $_SESSION['online'] = $db->getField("online"); $_SESSION['username'] = $username; // USERNAME SESSION $_SESSION['Admin'] = $db->getField("admin"); // ADMIN SESSION $_SESSION['userid'] = $db->getField("id"); // ID SESSION $_SESSION['isbanned'] = $db->getField("isbanned"); if($_SESSION['isbanned'] == 1){ echo "Your Account has been Banned,"; } else { header("location: profile.php"); } } } // END CLASS ?> Quote Link to comment Share on other sites More sharing options...
Alex Posted October 25, 2009 Share Posted October 25, 2009 The way to define a class is like: class Something { } Because the class itself doesn't take any parameters, rather any parameters being passed when instantiating the class are through the constructor. Quote Link to comment Share on other sites More sharing options...
.josh Posted October 25, 2009 Share Posted October 25, 2009 did you actually read the error? Quote Link to comment Share on other sites More sharing options...
jkewlo Posted October 25, 2009 Author Share Posted October 25, 2009 Ok I have gotten rid of that error now I am getting the error Parse error: syntax error, unexpected ';', expecting T_FUNCTION in /var/www/www.eve-lounge.com/htdocs/includes/data/user.class.php on line 123 line 123 is the closing php ?> tag.. I dont see any ; that are out of place.. <?php ###################### # MoJo Social Engine # # Function.class.php # ###################### session_start(); require_once('config.php'); require_once('database.php'); class user { public $username; public $password; public $vpassword; public $email; public $ip; public $fname; public $lname; public $age; public $id; private $_db; static private $_instance = null; private function __construct() { session_start(); } static public function getInstance() { if (self::$_instance == null) { self::$_instance = new user(); } return self::$_instance; } function register($username, $password, $email, $ip, $fname, $lname, $age) { if($action == "register") { $db = new Database(); if(!$username || !$password || !$vpassword || !$email || !$fname || !$lname || !$age) { return "ERROR_allfields"; } // END // IF USERNAME IS TAKEN $sql = "SELECT username FROM users WHERE username=$username"; if($sql > 0) { return "ERROR_Username"; } // END // IF $password matches $vpassword if($password != $vpassword) { return "ERROR_Password"; } // END if($email == "") { return "ERROR_Email"; } // END if($fname == "") { return "ERROR_First_Name"; } // END if($lname == "") { return "ERROR_Last_Name"; } // END if($age == "") { return "ERROR_Age"; } // END } } // END function Login($username, $password) { $db = new Database(); $sql = "SELECT * FROM users WHERE username=$username AND password=$password"; $db->query($sql); $date = date("Y-m-d H:i:s", time()); $sql1="UPDATE users SET online=1 WHERE username='". $username ."'"; $db->query($sql1); if($db->nextRecord()){ $_SESSION['status'] = 'logged'; // SESSION FOR USER BEING LOGGED! $_SESSION['auth'] = $db->getField("auth"); $_SESSION['online'] = $db->getField("online"); $_SESSION['username'] = $username; // USERNAME SESSION $_SESSION['Admin'] = $db->getField("admin"); // ADMIN SESSION $_SESSION['userid'] = $db->getField("id"); // ID SESSION $_SESSION['isbanned'] = $db->getField("isbanned"); if($_SESSION['isbanned'] == 1){ echo "Your Account has been Banned"; } else { header("location: profile.php"); } } function isLoggedIn() { if (isset($_SESSION['username']) && $_SESSION['auth'] === md5('auth')) { return true; } else { return false; } } } // END CLASS ?> Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted October 25, 2009 Share Posted October 25, 2009 you aren't closing your CLASS with a } proper indenting of your code would've helped you pick this up in a second .. probably would've prevented it. i don't know much about classes, but do you need to have session_start(); in your __construct as well as the top of your script? Quote Link to comment Share on other sites More sharing options...
jkewlo Posted October 25, 2009 Author Share Posted October 25, 2009 I didnt even notice I did that. thanks for pointing it out.. I am closing my class with a } its class user{ } // END CLASS Quote Link to comment Share on other sites More sharing options...
jkewlo Posted October 25, 2009 Author Share Posted October 25, 2009 I dont see where anything is wrong... or what function it is in.. Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted October 25, 2009 Share Posted October 25, 2009 you think you are, but you're not. that final } //END CLASS is closing the last function, not your class .. trust me. right now, download Notepad++ for syntax highlighting and use proper indenting. Quote Link to comment Share on other sites More sharing options...
jkewlo Posted October 25, 2009 Author Share Posted October 25, 2009 I have dreamweaver cs3 Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted October 25, 2009 Share Posted October 25, 2009 I have dreamweaver cs3 does it have syntax highlighting? if so, you'd see this. have you tried adding a final } to the script? Quote Link to comment Share on other sites More sharing options...
jkewlo Posted October 25, 2009 Author Share Posted October 25, 2009 yeah I had did that last night but I use winscp and sometimes it dosnt like to update to the server.. but This problem is solved.. now time for some more bugs >< Quote Link to comment Share on other sites More sharing options...
mrMarcus Posted October 25, 2009 Share Posted October 25, 2009 see why indenting (clean code) is so important? these kinds of mistakes are very avoidable. EDIT: ###################### # MoJo Social Engine # # Function.class.php # ###################### session_start(); require_once('config.php'); require_once('database.php'); class user() { public $username; public $password; public $vpassword; public $email; public $ip; public $fname; public $lname; public $age; public $id; private $_db; static private $_instance = null; private function __construct() { session_start(); } static public function getInstance() { if (self::$_instance == null) { self::$_instance = new Login(); } return self::$_instance; } function register($username, $password, $email, $ip, $fname, $lname, $age) { if($action == "register") { $db = new Database(); if(!$username || !$password || !$vpassword || !$email || !$fname || !$lname || !$age) { $_SESSION['error'] = "One or more of the fields was left empty, Please fill all fields out! Thanks o.O"; } // END // IF USERNAME IS TAKEN $sql = "SELECT username FROM users WHERE username=$username"; if($sql > 0) { return "ERROR_Username"; } // END // IF $password matches $vpassword if($password != $vpassword) { return "ERROR_Password"; } // END if($email == "") { return "ERROR_Email"; } // END if($fname == "") { return "ERROR_First_Name"; } // END if($lname == "") { return "ERROR_Last_Name"; } // END if($age == "") { return "ERROR_Age"; } // END } } // END function Login($username, $password) { $db = new Database(); $sql = "SELECT * FROM users WHERE username=$username AND password=$password"; $db->query($sql); $date = date("Y-m-d H:i:s", time()); $sql1="UPDATE users SET online=1 WHERE username='". $username ."'"; $db->query($sql1); if($db->nextRecord()) { $_SESSION['status'] = 'logged'; // SESSION FOR USER BEING LOGGED! $_SESSION['online'] = $db->getField("online"); $_SESSION['username'] = $username; // USERNAME SESSION $_SESSION['Admin'] = $db->getField("admin"); // ADMIN SESSION $_SESSION['userid'] = $db->getField("id"); // ID SESSION $_SESSION['isbanned'] = $db->getField("isbanned"); if($_SESSION['isbanned'] == 1){ echo "Your Account has been Banned,"; } else { header("location: profile.php"); } } } // END CLASS cleaned your code up .. you can now see the missing } to your class was actually the closing } for your last function. doing so really helps write/edit/troubleshoot your code and makes life so much easier Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.