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
Share on other sites

Your error has nothing to do with the fact that your code might be OOP. By the way, just because your using classes does not make your code OOP either.

 

Anyway, $reports isn't defined within your userLogin() function.

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.