Cronwerks MCCode/MCCodes Forums

Please login or register.

Login with username, password and session length

News:

Have you purchased a mod and lost your copy? Just file a support ticket through your "My Mods" page.


This forum is now closed and has moved to a new location! Click here to find out why.

AuthorTopic: shopadmin.php Call to a member function query() on a non-object  (Read 754 times)

Gori

  • Basic Member
  • *
  • Reputation Power: 5
  • Gori has no influence.
  • Offline Offline
  • Posts: 10
    • View Profile
why am i getting:

Fatal error: Call to a member function query() on a non-object in /home/mafia/public_html/shopadmin.php on line 259

i have this playershops mod thing a friend bought for me

below is the code thingy
Code: [Select]
<?php
/*-----------------------------------------------------
Copyright Dark City
Paid Modification
joshis.s@hotmail.co.uk
-----------------------------------------------------*/
include "globals.php";

$checkshop=$db->query("select count(*) as cnt from usershops where 

userid=$userid"
);
$cs=$db->fetch_row($checkshop);
if(
$cs['cnt']==0)
{
die(
"You dont have a shop. Go <a href=buyshop.php>here</a> to buy 

one."
);
}

switch(
$_GET['act'])
{
case 
'upgrade'upgrade(); break;

case 
'submitinfo'submitinfo(); break;

case 
'closeshop'closeshop(); break;

case 
'withdraw'withdraw(); break;

default: 
admin_index(); break;
}

function 
withdraw()
{
global 
$c$userid$ir;
if(!
$_POST['withdraw'])
{
$selinfo=$db->query("select * from usershops where userid=$userid");
$inf=$db->fetch_row($selinfo);
print
"<form action=shopadmin.php?act=withdraw method=post>
There is \${$inf['till']} in your shop till.<br>
How much would you like to withdraw?
<br><input class=textbox type=text name=amount><br>
<input class=textbox type=hidden name=withdraw value=1>
<input class=textbox type=submit value=Withdraw>
<Br>
<br>
<a href=shopadmin.php>Go Back</a>
"
;

}
else
{
$selinfo=$db->query("select * from usershops where userid=$userid");
$inf=$db->fetch_row($selinfo);
$withdraw=abs(strip_tags($_POST['amount']));
if(
$withdraw>$inf['till'])
{
die(
"There isnt that much in the till. <a href=shopadmin.php>Go 

Back</a>"
);
}
$db->query("update users set money=money+$withdraw where 

userid=$userid"
) or die($db->error());
$db->query("update usershops set till=till-$withdraw where 

userid=$userid"
) or die($db->error());
print
"You have successfully withdrawn $$withdraw from your shop 

till!"
;
}
}



function 
admin_index()
{
global 
$c$userid$ir;
$add=10;
$multiply=1000;
$selinfo=$db->query("select * from usershops where userid=$userid");
$inf=$db->fetch_row($selinfo);
$cost=($inf['shopsize']+$add)*($multiply);
print
"
<table class=table align=center width=450>
<tr><th colspan=2>Your Shop Admin Panel</th></tr>
<tr><td colspan=2><a href=shopindex.php?shop={$inf['shopid']}>View 

Your Shop</a></td></tr>
<tr><td>Change Shop Info</td><td><a href=shopadmin.php?

act=submitinfo>Change</a></td></tr>
<tr><td>Upgrade Shop</td><td><a href=shopadmin.php?

act=upgrade>Upgrade</a></td></tr>
<tr><td>Shop Till: \${$inf['till']}</td><td><a href=shopadmin.php?

act=withdraw>Withdraw</a></td></tr>
<tr><td>Shop Size: {$inf['shopsize']}</td><td>Upgrade Cost: 

$$cost</td></tr>
<tr><td>Close Shop</td><td><a href=shopadmin.php?act=closeshop>Close 

Shop</a> (!cant undo!)</td></tr>
"
;
}


function 
submitinfo()
{
global 
$c$userid$ir;
$p=$db->query("select * from cities");

$selinfo=$db->query("select * from usershops where userid=$userid");
$inf=$db->fetch_row($selinfo);
if(!
$_POST['subm'])
{
print
"<form action=shopadmin.php?act=submitinfo method=post>
<input type=hidden name=subm value=subm>
Shop Name: <input class=textbox type=text name=shopname value='{$inf

['shopname']}'>
<Br><br>
Shop Description:<br> <textarea class=textbox rows=10 cols=80 

name=description>{$inf['shopdescription']}</textarea>
<br><br>
Shop Location: <select class=textbox name=location>"
;


while(
$n=$db->fetch_row($p))
{
$selected="<option value={$n['cityid']}>";
if(
$inf['location']==$n['cityid'])
{
$selected="<option value={$n['cityid']} selected='selected'>";
}
print
"$selected{$n['cityname']}</option>";
}
print
"</select>
<Br><br><center>
<input class=textbox type=submit value='Update Shop'></center>
</form>
<br><br><a href=shopadmin.php>Back to Shop Admin Panel</a>"
;
}
else
{
if(!
$_POST['shopname'])
{
die(
"Your shop needs a name. <a href=shopadmin.php?act=submitinfo>Go 

Back</a>"
);
}

$selinfo=$db->query("select * from usershops where userid=$userid");
$inf=$db->fetch_row($selinfo);

$_POST['shopname']=strip_tags($_POST['shopname']);
$_POST['description']=strip_tags($_POST['description']);

$db->query("update usershops set shopname='{$_POST['shopname']}', 

shopdescription='{$_POST['description']}', location={$_POST

['location']} where shopid={$inf['shopid']}"
) or die($db->error());

print
"Shop Successfully Updated! <a href=shopadmin.php>Go Back</a>";
}
}

function 
upgrade()
{
global 
$c$userid$ir;
if(!
$_POST['subm'])
{
$multiply=1000;
$add=10;
$selinfo=$db->query("select * from usershops where userid=$userid");
$inf=$db->fetch_row($selinfo);
$cost=($inf['shopsize']+$add)*($multiply);
print
"
To upgrade your shop it will cost $$cost.<br><br>
Please choose how you want to pay for this.<Br>
Your Money: \${$ir['money']}<br>
Shop Till: \${$inf['till']}<br>
<form action=shopadmin.php?act=upgrade method=post>
<input type=hidden name=subm value=subm>
<select class=textbox name=payment>
<option value='till'>Shop Till</option>
<option value='money'>Your Money</option>
</select>
<input class=textbox type=submit value=Upgrade>
</form>
"
;
}
else
{
$multiply=1000;
$add=10;
$selinfo=$db->query("select * from usershops where userid=$userid");
$inf=$db->fetch_row($selinfo);
$cost=($inf['shopsize']+$add)*($multiply);
$payment=$_POST['payment'];
if(
$payment=="till")
{
$var=$inf['till'];
$table='usershops';
}
else if(
$payment=="money")
{
$var=$ir['money'];
$table='users';
}

if(
$var<$cost)
{
print
"You chose to pay for this with your $payment, but there is not 

enough to cover it. Please choose a different payment option.<br><a 

href=shopadmin.php?act=upgrade>Go Back</a>"
;
}
else
{
$db->query("update $table set $payment=$payment-$cost where 

userid=$userid"
) or die($db->error());
$db->query("update usershops set shopsize=shopsize+1 where 

userid=$userid"
) or die($db->error());

print
"Shop Upgraded Successfully! <a href=shopadmin.php>Go Back</a>";
}
}
}
function 
closeshop()
{
global 
$c$userid$ir;
if(!
$_GET['delete'])
{
print
"Are you sure you want to shut down your shop? <Br><br>You will 

not get any money back for the upgrades you have made, any money in 

the shop till will be lost along with any items you may still have 

for sale in the shop.<Br><br>
<a href=shopadmin.php?act=closeshop&delete=1>Yes, I am sure. Close my 

shop.</a><br><br>
<a href=shopadmin.php>No, I dont want to close my shop!</a>
"
;
}
if(
$_GET['delete']==1)
{

$selinfo=$db->query("select * from usershops where userid=$userid");
$inf=$db->fetch_row($selinfo);

$db->query("delete from usershoppitems where shopid={$inf

['shopid']}"
);
$db->query("delete from usershops where userid=$userid");

print
"You have closed down your shop.<Br>If you want to open a new 

shop you can now do so."
;
}
}






?>


Logged

Zeddicus

  • Basic Member
  • *
  • Reputation Power: 0
  • Zeddicus is looked down upon.Zeddicus is looked down upon.
  • Offline Offline
  • Posts: 42
    • View Profile
    • WWW
Re: shopadmin.php Call to a member function query() on a non-object
« Reply #1 on: December 12, 2009, 10:16:50 AM »
Just 'skimmed' the code, it looks like you haven't defined the '$db' variable.

Also that code is *very* insecure, i wouldn't advise using it...
Logged

Gori

  • Basic Member
  • *
  • Reputation Power: 5
  • Gori has no influence.
  • Offline Offline
  • Posts: 10
    • View Profile
Re: shopadmin.php Call to a member function query() on a non-object
« Reply #2 on: December 12, 2009, 10:32:52 AM »
could u tell me how to define it

and how can i make it secure?
Logged

Danny696

  • Senior Member
  • ****
  • Reputation Power: 317
  • Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.
  • Offline Offline
  • Posts: 540
    • View Profile
    • WWW
Re: shopadmin.php Call to a member function query() on a non-object
« Reply #3 on: December 12, 2009, 12:14:18 PM »
on line 239, replace: global $c$userid$ir; with this: global $c$userid$ir$db; if you pm me, ill secure it.
Logged
Project Choosen - 10%
Daniel - Hanson . Com

Gori

  • Basic Member
  • *
  • Reputation Power: 5
  • Gori has no influence.
  • Offline Offline
  • Posts: 10
    • View Profile
Re: shopadmin.php Call to a member function query() on a non-object
« Reply #4 on: December 12, 2009, 02:57:48 PM »
i fixed it and now it shows up but i can't click on the links

Change
Upgrade
Withdraw
Logged

Danny696

  • Senior Member
  • ****
  • Reputation Power: 317
  • Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.Danny696 is a force to reckon with.
  • Offline Offline
  • Posts: 540
    • View Profile
    • WWW
Re: shopadmin.php Call to a member function query() on a non-object
« Reply #5 on: December 13, 2009, 05:00:15 AM »
Give me about 20 mins, ill re-code it.
Logged
Project Choosen - 10%
Daniel - Hanson . Com
 


This forum is now closed and has moved to a new location! Click here to find out why.