katarra Posted March 9, 2010 Share Posted March 9, 2010 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> Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/ Share on other sites More sharing options...
nafetski Posted March 9, 2010 Share Posted March 9, 2010 "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! Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023895 Share on other sites More sharing options...
katarra Posted March 9, 2010 Author Share Posted March 9, 2010 I added $dbh=dbconnect(); and same error. Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023900 Share on other sites More sharing options...
nafetski Posted March 9, 2010 Share Posted March 9, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023904 Share on other sites More sharing options...
katarra Posted March 9, 2010 Author Share Posted March 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023905 Share on other sites More sharing options...
nafetski Posted March 9, 2010 Share Posted March 9, 2010 Do me a favor... print_r($dbh); and post the results here. Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023907 Share on other sites More sharing options...
PFMaBiSmAd Posted March 9, 2010 Share Posted March 9, 2010 And $dbh is being initiated as an object in function.s. No, it's not, as the error clearly indicates. You would need to debug why it is not being created. I would start by looking at the php code in function.s Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023909 Share on other sites More sharing options...
katarra Posted March 9, 2010 Author Share Posted March 9, 2010 print $dbh: Resource id #28 Fatal error: Call to a member function execute() on a non-object in /home/katarra/public_html/game.php on line 57 Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023911 Share on other sites More sharing options...
Anti-Moronic Posted March 9, 2010 Share Posted March 9, 2010 Another idea is that maybe this is using a package which isn't available in your current environment like PEAR::DB. ..but yeh, search the entire code for "$dbh =" if you can't find it within the obvious files. No, use print_r($dbh); not print Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023913 Share on other sites More sharing options...
nafetski Posted March 9, 2010 Share Posted March 9, 2010 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) Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023914 Share on other sites More sharing options...
katarra Posted March 9, 2010 Author Share Posted March 9, 2010 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. Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023916 Share on other sites More sharing options...
Anti-Moronic Posted March 9, 2010 Share Posted March 9, 2010 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! Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023922 Share on other sites More sharing options...
katarra Posted March 9, 2010 Author Share Posted March 9, 2010 Fantastic! Thank you! Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023924 Share on other sites More sharing options...
Anti-Moronic Posted March 9, 2010 Share Posted March 9, 2010 Oh, and that book above is like 6 years out of date but it really is one of the greatest introductions to OOP in php. Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023926 Share on other sites More sharing options...
nafetski Posted March 9, 2010 Share Posted March 9, 2010 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 Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023929 Share on other sites More sharing options...
katarra Posted March 9, 2010 Author Share Posted March 9, 2010 I've actually pulled lots of peoples codes, just have to learn how everything matches up since all the variables are different. Quote Link to comment https://forums.phpfreaks.com/topic/194697-fatal-error-help/#findComment-1023930 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.