Jump to content

Fatal Error Help


katarra

Recommended Posts

I am getting this error:

 

Fatal error: Call to a member function execute() on a non-object in /home/katarra/public_html/game.php on line 53

 

Any help would be greatly appreciated! Thanks in advance!!!

 

Here is the script:

<?
session_start();
include('adodb/adodb.inc.php');
define("PAGENAME", "Home");
?>
<html>
<head>
<title>The Worlds of Katarra</title>
<link rel=stylesheet type=text/css href=style.css>
<script language="javascript" type="text/javascript">

setTimeout(
function() 
{
var mytext = document.getElementById("rptext");
mytext.focus();
mytext.select();
}
, 1);
</script>
</head>
<?
require("scripts/function.s");

$loginname = ucwords(strtolower($loginname));
if ($loginname == " ") die("You didn't enter your username. Please go back and do so, or create a new character <a href=\"index1.html?page=register\">here</a>.<br>\n");
if (!isuser($loginname)) die("That username does not exist. To create it, click <a href=\"index1.html?page=register?username=$loginname\">here</a>.<br>");
$username = $loginname;
$encrypted = md5($loginpass);
if (get("password") !== md5(md5($loginpass))) die("Incorrect password.<br>\n");
addlogin($loginname,$loginpass,$REMOTE_ADDR);
if(!is_numeric(get("admin"))){
$timelog=getfile("timelog");
$timelog.="$loginname:in:".time()."\n";
setfile("timelog",$timelog);
}

//Begin checking if user has tried to login
$error = 0; //Error count
$errormsg = "<font color=\"red\">"; //Error message to be displayed in case of error (modified below depending on error)
if ($loginname == "")
{
	$errormsg .= "Please enter a username!";
	$error = 1;
}
else if ($loginpass == "")
{
	$errormsg .= "Please enter your password!";
	$error = 1;
}
else if ($error == 0)
{
	$query = $dbh->execute("select `id`, `username` from `users` where `username`=? and `password`=?", array($loginname, sha1($loginpass)));
	if ($query->recordcount() == 0)
	{
		$errormsg .= "You could not login! Please check your username/password!";
		$error = 1;
	}
	else
	{
		$player = $query->fetchrow();
		$query = $dbh->execute("update `users` set `last_active`=? where `id`=?", array(time(), $player['id']));
		$hash = sha1($player['id'] . $_SERVER['REMOTE_ADDR'] . $secret_key);
		$sdlkfj = 12;
		$_SESSION['userid'] = $player['id'];
		$_SESSION['hash'] = $hash;
	}
}
$errormsg .= "</font>";

$asdf = 0;
$charsdata = getfile("online");
if (strpos($charsdata,"$loginname:") !== false) $asdf = 1;
$charsdata = str_replace("$loginname:","",$charsdata)."$loginname:";
setfile("online",$charsdata);
$framesize = get("frame");
$encrypted = md5($loginpass);
echo "<frameset rows=\"".$framesize."%,*,0\" border=0>\n<frame name=\"TOP\" ";
if ($asdf == 1){
echo "src=\"main.php?username=$loginname&password=$encrypted\"";
}else{
echo "src=\"main.php?username=$loginname&password=$encrypted&isloggingin=1\"";
}
echo " noresize>\n<frame name=\"BOTTOM\" src=\"command.php?x=$loginname&y=$encrypted\" noresize scrolling=no>\n<frame name=CHECKER src=chatchek.php?username=$loginname&password=$encrypted noresize></frameset>\n";
set("lasttell","");
?>
</html>

Link to comment
Share on other sites

"Fatal error: Call to a member function execute() on a non-object in /home/katarra/public_html/game.php on line 53"

 

:)

 

Ok, so what this error is saying is "You are calling the function execute on something that isn't an object".

 

the $dbh variable, I'm not seeing where you are initializing it as a new object

(for example $dbh = new Game()

 

Since i'ts not an object, you don't have access to using the "->" operator. 

 

Let me know if this helps!

Link to comment
Share on other sites

Are you ever initializing $dbh as an object?  I am not seeing that anywhere. 

 

 

If not, you can't use it as an object...that is what the PHP error is trying to tell you.  Did you write this code?  If so I'd be more than happy to take some time and help you debug it...if not, and you're just biting off more than you can chew...take a look at some OOP tutorials and move from there!

Link to comment
Share on other sites

I've modified most of this, yes. *laughs* Corrected myself.

 

But, I'd love to learn OOP, just this is set to go live at the end of the month, and I don't think I have time to write the entire thing over. :)

 

And $dbh is being initiated as an object in function.s.

Link to comment
Share on other sites

Ok, so if print_r($dbh) is not showing itself as an object, then it's not an object.  The poster above me has said it...you have to debug where the object gets initialized.  The code you've posted may or not be correct, but your error is happening from something happening further upstream (I'd bet money on function.s.php which..makes me wonder if the file is being included at all.  Strange naming convention)

Link to comment
Share on other sites

I'll check the function.s script.

 

Thanks!

 

And if someone wants to help me learn OOP, I'd be indebted! *laughs*

 

And yes, odd naming is my game.

 

Believe me, don't aspire to learn how to use OOP from strangers on a forum (and I mean with NO disrespect to the great developers here). What you should do is go out there and get yourself a great, up-to-date book which discusses the principles of OOP in php and gives you plenty of examples and food for thought.

 

I got lost myself on the principles until the book I read gave me real world implementations. It made everything click.

 

The book was :

 

PHP 5 Objects, Patterns, and Practice ( Matt Zandstra).

 

Get that and read it over and over. You will be a php magician in no time! :)

Link to comment
Share on other sites

:) 

 

Agreed. 

 

You're doing the right thing tho...as a developer you learn by doing, and in our world you're only doing if you're writing code!

 

The only thing that I wish I did differently in my development career was spend more time reading OTHER peoples code (rather than banging my head on my own).  If you take a look at open source PHP projects (like, wordpress, or other large scale PHP applications) and look through their code it really opens your eyes up on not just how to make things work...but how to do things correctly.

 

Read forums, do tutorials, challenge yourself, and read other peoples code.  It's how we all got/get better :)

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.