Jump to content

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/169416-member-function-execute-on-a-non-object/
Share on other sites

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?

 

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.

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) 

 

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.  :facewall:  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>";

?>

 

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;
	}
}
}

?>

 

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!

 

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

?>

 

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!

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.