Jump to content

Cannot access empty property


jkewlo

Recommended Posts

Hello I am trying to get better at OOP PHP and I am getting this error

 

Fatal error: Cannot access empty property in /var/www/www.eve-lounge.com/htdocs/v2/data/function.class.php on line 38

 

line 38 is

 

$this->dbNotificationTable = 'notification';

 

here is all of my function.class.php

 

notification is a table in the database

 

<?php
############################
##        For the MoJo Social              ##
##                Engine		            ##
############################

class User {

var $userID,
	$username,
	$password,
	$sex,
	$email,
	$ip,
	$age,
	$dbHost,
	$dbUser,
	$dbName,
	$dbPass,
	$dbUserTable,
	$dbPostTable,
	$dbFollowingTable,
	$dbBoardTable,
	$dbNotificationTable,
	$dbNewsTable,
	$dbMessageTable,
	$dbChatTable;

function User() {
	$this->dbHost = '**';
	$this->dbUser = '**';
	$this->dbName = '**';
	$this->dbPass = '**';
	$this->dbUserTable = 'users';
	$this->dbPostTable = 'post';
	$this->dbFollowingTable = 'following';
	$this->dbBoardTable = 'board';
	$this->$dbNotificationTable = 'notification';
	$this->$dbNewsTable = 'news';
	$this->$dbMessageTable = 'message';
	$this->$dbChatTable = 'chat';
}
    //clean input
    function sanatize($data)
    {
        $data = stripslashes($data);
        $data = htmlentities($data);
        $data = mysql_escape_string($data);
        
        return $data;
    }
    
    //hash + salt function
    function hashIt($data)
    {
        $salt = "R3\£41d*7\"2$,.";
        $data = $data . $salt;
        $data = sha1($data);
        
        return $data;
    }
    
    //update lastclick in database
    function lastClick()
    {
        $username = $_SESSION['username'];
        $sql = mysql_query("UPDATE `users` SET lastclick = 'NOW()' WHERE username = '$username'");
    }
    
    //insert user info stored in database into sessions
    function userSessions()
    {
        global $username;
        $sql = mysql_query("SELECT * FROM `users` WHERE username = '$username'");
        $data = mysql_fetch_array($sql);
        
        $_SESSION['username'] = $username;
        // STORE USERNAME
        $_SESSION['status'] = 'logged';
        // SESSION FOR USER BEING LOGGED!
        $_SESSION['online'] = $data['lastclick'];
        $_SESSION['Admin'] = $data['admin'];
        // ADMIN SESSION
        $_SESSION['userid'] = $data['id'];
        // ID SESSION
        $_SESSION['isbanned'] = $data['isbanned'];
        // USER BANNED
    }
    
    //check if the user is banned
    function banCheck()
    {
        if ($_SESSION['isbanned'] == 1) {
            
            header("location: banned.php");
            exit();
        }
    }
    
    //check username and password
    function checkUser()
    {
	$dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
	if(!dbLink) die("Could Not Connect to database. ". mysql_error());

	$mysql_select_db($this->$dbName);

        $username = sanatize($_POST['username']);
        $password = sanatize($_POST['password']);
        $password = hashIt($password);
        
        $sql = "SELECT * FROM `$this->dbUserTable` WHERE username = '$username' AND password = '$password'";
        $result = mysql_num_rows($sql);
        
        if ($result = 1) {
            banCheck();
            userSessions();
            lastClick();
            header("location: profile.php");
        } else {
            echo "Wrong username and/or password";
            echo $username . "<br />";
            echo $password . "<br />";
        }
        
        
    }
    
    function registerUser($username, $password, $sex, $email, $ip) {
	// Connect to database
	$dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
	if(!$dbLink) die("Could not connect to database. " . mysql_error());

	// Select database
	mysql_select_db($this->dbName);

	// Insert data
	// Notice the "$userName" and "$userPassword" - these are the ones
	// passed in from your main script, not the class/object variables!
	// Salt the password before entering it into the databse with the hash and sha1() 
	$password = sanatize($_POST['password']);
	$password = hashIt($password);

	//check if there is already an account with this username
	$usernamequery = "SELECT * FROM `$this->dbUserTable` WHERE username = '$username'";
	$usernameresult = mysql_num_rows(mysql_query($usernamequery));
	//check if there is already an account with this email
	$emailquery = "SELECT * FROM `$this->dbUserTable` WHERE email = '$email'";
	$emailresult = mysql_num_rows(mysql_query($emailquery));

	//if username already exists tell user, if email already exists tell user
	if ($usernameresult > 0){
	exit ("Sorry, an account with the username <b><i>$username</i></b> already exists.<br />");
	}
	elseif ($emailresult > 0){
	exit ("Sorry, an account is already registered with the email address <b><i>$email</i></b>.<br />");
	}
	//else insert user data into database
	else{

	$query = "INSERT INTO $this->dbUserTable(username, sex, email, password, ip) VALUES ('$username', '$sex', '$email', '$password', '$ip')";
	$result = mysql_query($query);

	// Test to make sure query worked
	if(!$result) die("Query didn't work. " . mysql_error());

	// Get the user ID
	$this->userID = mysql_insert_id();

	// Close database connection
	mysql_close($dbLink);

	// Assign the values to the data members
	$this->username = $username;
	$this->password = $password;
	$this->sex = $sex;
	$this->email = $email;
	$this->ip = $_SERVER["REMOTE_ADDR"];
	}
} // End registerUser()

function displayUserInfo() {
	echo '<b>User ID: </b>' . $this->userID . '<br>';
	echo '<b>User Name: </b>' . $this->username . '<br>';
	echo '<b>User Password: </b>' . $this->password . '<br>';
	echo '<strong><font color=green>Your Account had been created. please <a href="index.php">Log In!</a>';
} // End displayUserInfo()
    
function verifyPassword() {
	// Remember, by the time this method is called, your main script will have already 
	// put the userName and userPassword variables equal to the ones the user typed in

	// Connect to database
	$dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
	if(!$dbLink) die("Could not connect to database. " . mysql_error());

	// Select database
	mysql_select_db($this->dbName);

	// Get data
	$query = "select password from $this->dbUserTable where username = \"$this->username\"";
	$result = mysql_query($query);

	// Test to make sure query worked
	if(!$result) die("Query didn't work. " . mysql_error());

	// Get the password from the database
	$actualPassword = mysql_result($result, 0);

	// Verify that they match
	if(!($actualPassword == $this->password)) die("Incorrect Password.");

	// Close database connection
	mysql_close($dbLink);
} // End verifyPassword()

function changePassword($newPassword) {
	// This function assumes you've already verified that the user has
	// permission to change the password - it recieves the new password
	// as an argument, with the old password already registered in $userPassword

	// Connect to database
	$dbLink = mysql_connect($this->dbHost, $this->dbUser, $this->dbPass);
	if(!$dbLink) die("Could not connect to database. " . mysql_error());

	// Select database
	mysql_select_db($this->dbName);

	// Get data
	$query = "update $this->dbUserTable set password = \"$newPassword\" where username = \"$this->username\"";
	$result = mysql_query($query);

	// Test to make sure query worked
	if(!$result) die("Query didn't work. " . mysql_error());

	// It worked, so update the password stored in the object
	$this->password = $newPassword;

	// Close database connection
	mysql_close($dbLink);		
} // End changePassword()

  };


class DateIntervalFormat
{
    
    public function getInterval($timestamp, $granularity = 2)
    {
        $seconds = time() - $timestamp;
        $units = array('1 year|:count years' => 31536000,
        '1 week|:count weeks' => 604800,
        '1 day|:count days' => 86400,
        '1 hour|:count hours' => 3600,
        '1 min|:count minuntes' => 60,
        '1 sec|:count seconds' => 1);
        $output = '';
        foreach($units as $key => $value) {
            $key = explode('|', $key);
            if ($seconds >= $value) {
                $count = floor($seconds / $value);
                $output .= ($output ? ' ' : '');
                $output .= ($count == 1) ? $key[0] : str_replace(':count', $count, $key[1]);
                $seconds %= $value;
                $granularity--;
            }
            if ($granularity == 0) {
                break;
            }
        }
        
        return $output ? $output : '0 sec';
    }
};

function showNews(){
        $sql="SELECT `subject`, `id`, `body`, stamp FROM news ORDER BY ID DESC LIMIT 0, 1";
        $result=mysql_query($sql);
        while ($rows=mysql_fetch_array($result)) {
            echo "<p><strong>". $rows['subject'] ."</strong>";
            $dateFormat = new DateIntervalFormat();
            $timestamp = strtotime($rows['stamp']);
            
            echo sprintf('<b><font color=#cccccc> %s ago</font></b><hr>',  $dateFormat->getInterval($timestamp));
            echo "</p><p>". $rows['body'] ."</p>";
        }
    }



?>

Link to comment
https://forums.phpfreaks.com/topic/174004-cannot-access-empty-property/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.