katarra Posted August 9, 2009 Share Posted August 9, 2009 I'm getting this error: Fatal error: Call to a member function execute() on a non-object in /home/katarra/public_html/fishing.php on line 12 Here is my coding: <?php /*************************************/ /* ezRPG mod */ /* JR DeLaney */ /*************************************/ define("PAGENAME", "Fishing"); if ($_GET['act'] == "fish") { $query = $db->execute("select * from `users` where `username`=?", array($_SESSION['userid'])); return $users; if ($users->pole < 1) { echo "You do not have a fishing pole! <br />Go to the <a href=\"fishstore.php\">Fish Store</a> to buy a pole.<br /><br />"; echo "<img src='images/fishing.jpg'>"; exit; } else { echo "<img src='images/fishing.jpg'><br />"; exit; $effect[0] = "caught a fish.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[1] = "caught a boot.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[2] = "caught a big fish.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[3] = "caught a fish.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[4] = "caught a tire.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[5] = "caught a tire.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[6] = "caught a boot.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[7] = "caught a Duck.<br /><a href=\"fishing.php?act=fish\">Keep fishing?"; $effect[8] = "caught a boot.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $randeffect = array_rand($effect); $randoutput = $effect[$randeffect]; $blurb = "<p>You throw in your line and you:<br>"; } } echo "<a href=\"fishing.php?act=fish\">Start fishing!</a>"; ?> Any help? I've been at this for a few hours trying to figure it out... I basically want it go into the mysql database and pull to see if a user has a fishing pole equipped or not. Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/ Share on other sites More sharing options...
MadTechie Posted August 9, 2009 Share Posted August 9, 2009 $db isn't being set you should have something like $db = new ..blar.. Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/#findComment-893849 Share on other sites More sharing options...
katarra Posted August 9, 2009 Author Share Posted August 9, 2009 k Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/#findComment-893853 Share on other sites More sharing options...
katarra Posted August 9, 2009 Author Share Posted August 9, 2009 Okay, I added: $db = ('users'); And got this: Fatal error: Call to a member function execute() on a non-object in /home/katarra/public_html/fishing.php on line 13 Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/#findComment-893854 Share on other sites More sharing options...
MadTechie Posted August 9, 2009 Share Posted August 9, 2009 Erm.. okay is users a class ? where did you get $db = ('users'); from ? Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/#findComment-893859 Share on other sites More sharing options...
katarra Posted August 9, 2009 Author Share Posted August 9, 2009 I added it to the file. <?php /*************************************/ /* ezRPG mod */ /* JR DeLaney */ /*************************************/ define("PAGENAME", "Fishing"); if ($_GET['act'] == "fish") $db = new $query = $db->execute("select * from `users` where `username`=?", array($_SESSION['userid'])); return $users; if ($users->pole < 1) { echo "You do not have a fishing pole! <br />Go to the <a href=\"fishstore.php\">Fish Store</a> to buy a pole.<br /><br />"; echo "<img src='images/fishing.jpg'>"; exit; } else { echo "<img src='images/fishing.jpg'><br />"; exit; $effect[0] = "caught a fish.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[1] = "caught a boot.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[2] = "caught a big fish.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[3] = "caught a fish.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[4] = "caught a tire.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[5] = "caught a tire.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[6] = "caught a boot.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[7] = "caught a Duck.<br /><a href=\"fishing.php?act=fish\">Keep fishing?"; $effect[8] = "caught a boot.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $randeffect = array_rand($effect); $randoutput = $effect[$randeffect]; $blurb = "<p>You throw in your line and you:<br>"; } } echo "<a href=\"fishing.php?act=fish\">Start fishing!</a>"; ?> users is the database table that this information is stored in. Is that wrong? Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/#findComment-893866 Share on other sites More sharing options...
katarra Posted August 9, 2009 Author Share Posted August 9, 2009 If anything, if I could fix this file, I would be in PARADISE! <?php /*************************************/ /* ezRPG script */ /* Written by Zeggy */ /* http://code.google.com/p/ezrpg */ /* http://www.ezrpgproject.com/ */ /*************************************/ //Function to check if user is logged in, and if so, return user data as an object function check_user($secret_key, &$db) { if (!isset($_SESSION['userid']) || !isset($_SESSION['hash'])) { exit; } else { $check = sha1($_SESSION['userid'] . $_SERVER['REMOTE_ADDR'] . $secret_key); if ($check != $_SESSION['hash']) { session_unset(); session_destroy(); exit; } else { $query = $db->execute("select * from `users` where `username`=?", array($_SESSION['userid'])); $userarray = $query->fetchrow(); if ($query->recordcount() == 0) { session_unset(); session_destroy(); exit; } foreach($userarray as $key=>$value) { $user->$key = $value; } return $user; } } } ?> This is the file that everything links to, and up above, I'm just fixing it by individual file by individual file... I need a way to make the users info become an object, and I've never done that before. Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/#findComment-893869 Share on other sites More sharing options...
MadTechie Posted August 9, 2009 Share Posted August 9, 2009 Okay as i haven't used that system before this is partly guess work but i think $db = new $query = $db->execute("select * from `users` where `username`=?", array($_SESSION['userid'])); return $users; if ($users->pole < 1) should be something like require_once("lib.php"); $users = check_user($secret_key, $db); $query = $db->getone("select * from `users` where `username`=?", array($_SESSION['userid'])); if ($query['pole'] < 1) Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/#findComment-893874 Share on other sites More sharing options...
katarra Posted August 9, 2009 Author Share Posted August 9, 2009 I got: Fatal error: Call to undefined function check_user() in /home/katarra/public_html/fishing.php on line 11 And this, I believe, is from not having the function check_user setup. That's what my main problem is. I need somehow to return the user data as an object. I've been working for a while at that, and that is the major stumbling block I've come up with. <?php /*************************************/ /* ezRPG mod */ /* JR DeLaney */ /*************************************/ define("PAGENAME", "Fishing"); if ($_GET['act'] == "fish") require_once("lib.php"); $users = check_user($secret_key, $db); $query = $db->getone("select * from `users` where `username`=?", array($_SESSION['userid'])); if ($query['pole'] < 1) { echo "You do not have a fishing pole! <br />Go to the <a href=\"fishstore.php\">Fish Store</a> to buy a pole.<br /><br />"; echo "<img src='images/fishing.jpg'>"; exit; } else { echo "<img src='images/fishing.jpg'><br />"; exit; $effect[0] = "caught a fish.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[1] = "caught a boot.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[2] = "caught a big fish.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[3] = "caught a fish.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[4] = "caught a tire.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[5] = "caught a tire.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[6] = "caught a boot.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $effect[7] = "caught a Duck.<br /><a href=\"fishing.php?act=fish\">Keep fishing?"; $effect[8] = "caught a boot.<br /><a href=\"fishing.php?act=fish\">Keep fishing?</a>"; $randeffect = array_rand($effect); $randoutput = $effect[$randeffect]; $blurb = "<p>You throw in your line and you:<br>"; } echo "<a href=\"fishing.php?act=fish\">Start fishing!</a>"; ?> Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/#findComment-893878 Share on other sites More sharing options...
MadTechie Posted August 9, 2009 Share Posted August 9, 2009 check_user is in the function.php thats included in the lib.php which also included the config.php Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/#findComment-893882 Share on other sites More sharing options...
katarra Posted August 9, 2009 Author Share Posted August 9, 2009 I pasted the function.php, but I can't seem to get the variables filled in correctly. I don't need the header stuff, so when I delete it, it messes other things up. Also, where does the 'userid' thing come from? I don't have that as any values in any of my tables. <?php /*************************************/ /* ezRPG script */ /* Written by Zeggy */ /* http://code.google.com/p/ezrpg */ /* http://www.ezrpgproject.com/ */ /*************************************/ //Function to check if user is logged in, and if so, return user data as an object function check_user($secret_key, &$db) { if (!isset($_SESSION['userid']) || !isset($_SESSION['hash'])) { header("Location: index.php"); exit; } else { $check = sha1($_SESSION['userid'] . $_SERVER['REMOTE_ADDR'] . $secret_key); if ($check != $_SESSION['hash']) { session_unset(); session_destroy(); exit; } else { $query = $db->execute("select * from `users` where `username`=?", array($_SESSION['userid'])); $userarray = $query->fetchrow(); if ($query->recordcount() == 0) { session_unset(); session_destroy(); exit; } foreach($userarray as $key=>$value) { $user->$key = $value; } return $user; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/#findComment-893886 Share on other sites More sharing options...
MadTechie Posted August 9, 2009 Share Posted August 9, 2009 I pasted the function.php, but I can't seem to get the variables filled in correctly. I have already said its check_user($secret_key, $db) you can see both are set in the config.php file! I don't need the header stuff, so when I delete it, it messes other things up. Erm..are you sure you know what your doing ? Also, where does the 'userid' thing come from? I don't have that as any values in any of my tables. userid is set in a session! so I'll assume its being set earlier in the code! Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/#findComment-893894 Share on other sites More sharing options...
katarra Posted August 9, 2009 Author Share Posted August 9, 2009 I have a good idea what I'm doing, but learning on the fly. And as for the config.php file, there isn't much to it, just a database connection beginning and some other extension crap I don't think I need. It doesn't set the check_user($secret_key, $db) function at all. Thus why I'm having a pain in the ass time trying to fix it. <?php /*************************************/ /* ezRPG script */ /* Written by Zeggy */ /* http://code.google.com/p/ezrpg */ /* http://www.ezrpgproject.com/ */ /*************************************/ $config_server = "localhost"; //Database host $config_database = "zrpg"; //Database name $config_username = "root"; //Database username $config_password = ""; //Database password $secret_key = "mysecret"; //Secret key, make it a random word/sentence/whatever //Do not edit below this line $version = "0.12"; include('adodb/adodb.inc.php'); //Include adodb files $db = &ADONewConnection('mysql'); //Connect to database $db->Connect($config_server, $config_username, $config_password, $config_database); //Select table $db->SetFetchMode(ADODB_FETCH_ASSOC); //Fetch associative arrays $ADODB_FETCH_MODE = ADODB_FETCH_ASSOC; //Fetch associative arrays //$db->debug = true; //Debug ?> Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/#findComment-893906 Share on other sites More sharing options...
katarra Posted August 9, 2009 Author Share Posted August 9, 2009 Anybody offer to help for maybe 5 minutes that knows what they're doing. I'm doing this right now over this stupid thing... Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/#findComment-894176 Share on other sites More sharing options...
MadTechie Posted August 9, 2009 Share Posted August 9, 2009 I think you have an older version as looking at the config.php (I downloaded to help you) you need everything! it also sounds like you have messed around with it so who know what the problem could be now, as the changes your trying to do are not massive changes and should be simple! Quote Link to comment https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/#findComment-894245 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.