Jump to content

[SOLVED] Parse error: syntax error


jkewlo

Recommended Posts

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

?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

?>

 

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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 :P

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.