Jump to content

OOP error


Twister1004

Recommended Posts

Hey everyone!

 

I'm starting to rewrite my code for my website and I'm understanding OOP more and more (since I had a class on it), however, I just can't seem to figure out what is going wrong with the code and my login script as to why it is not running my object, when its been declaired.

 

Here are the required parts of the files that is required  for this OOP code im working on.

 

Login Function (Not writen in OOP yet)

File: functions.php

function userLogin($username, $pass){
$checkUser = mysql_query("SELECT * FROM `accounts` WHERE `username` = '".$username."' LIMIT 1");
if(mysql_num_rows($checkUser) == 1){
	while($User = mysql_fetch_array($checkUser)){
		if(hash('sha512', $pass) == $User['password']){
			if(!@$_SESSION['id']){
				//More Dynamic way other than SESSIONS are needed for updated accounts
				//Add security to banned accounts
				$_SESSION['id'] = $User['user_id'];
				$_SESSION['user'] = $User['username'];
				$_SESSION['permission'] = $User['clearence'];
				$_SESSION['isArtist'] = $User['isArtist'];
				$_SESSION['artistType'] = $User['artistType'];
				$_SESSION['lastlogin'] = $User['lastlogin'];
				$_SESSION['loginTime'] = time();
				$_SESSION['artistTypeName'] = artistType($_SESSION['artistType']);
				$updateIP = mysql_query("UPDATE `accouns` SET `lastip` = '".$_SERVER['REMOTE_ADDR']."' WHERE `user_id` = '".$_SESSION['id']."'"); 
                                        //This is a SQL error by the wrong table and it is purposefully done for testing my OOP Code.
				$updateLogin = mysql_query("UPDATE `accounts` SET `lastlogin` = '".time()."' WHERE `user_id` = '".$_SESSION['id']."' LIMIT 1");
				if(!$updateIP){
					$reports->Error("Failure to update IP in login: ".mysql_error(), $_SERVER['REQUEST_URI']);
                                                // ~~~~~~~~~~~~~~~~~ THIS IS LINE 24 ~~~~~~~~~~~~~~~~~
					logout(0);
					die();
				}
				if(!$updateLogin){
					sendError(mysql_error(), $_SERVER['REQUEST_URI']);
					logout(0);
				}
				echo "<meta http-equiv=\"refresh\" content=0; url=\"\"/>";
			}
			else break;
		} 
		else{
			echo "<font color='red'>Username or Password is incorrect.</font>";
		}
	}
}
else{
	echo "<font color='red'>Username or Password is incorrect.</font>";
}
}

 

File: includes.php

include("./inc/classes/reports.php");
include("./inc/database.php");
include("./inc/functions.php");
include("./inc/artclass.php");
//include("./inc/classes/loginsystem.php");

//$login = new Login(time());
$reports = new Reports();

 

File:Reports.php

<?php
class Reports{

public function Error($error, $page){
	$error = mysql_real_escape_string($error);
	$page = mysql_real_escape_string($page);

	$sendError = mysql_query("INSERT INTO `errors` (errorCode, page, date)
		VALUES ('".$error."', '".$page."', '".time()."')");
		//date("F m, Y -- h:i:s")

	if(!$sendError){
		$this->Message(0);
	}
	else{
		$this->Message(2);
	}

}

public function Report(){

}

public function Query($Table, $Comment, $Page, $Date){
	// NOT inplemented
}

private function Message($number){
	switch($number){
		case 0:
			echo "There was an error reporting an issue. Please alert us by <a href='contact.php'>contacting us</a>.";
			break;
		case 1:
			echo "There was an error sending a report. Please use the <a href='contact.php'>contact us</a> and let us know!";
			break;
		case 2:
			echo "There was an error. Please wait about 30 minutes to retry your request.<br/><br/> We apologize for the inconvience.";
			break;
	}
}
}
?>

 

The Error:

Notice: Undefined variable: reports in functions.php on line 23

Fatal error: Call to a member function Error() on a non-object in functions.php on line 23

 

 

Any help would be very much appreciated!

Link to comment
https://forums.phpfreaks.com/topic/254561-oop-error/
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.