Author Topic: Inventory Error  (Read 909 times)

Offline snw

  • Level 5
  • *
  • Posts: 15
  • Reputation: +0/-0
    • View Profile
Inventory Error
« on: May 27, 2010, 06:56:51 AM »
hello  ;D
i started making my own browser game so i dl'ed that one from buildingbrowsergames.com
but my inventory php doesnt work  :-\
it gives my this  

Code: [Select]
Warning: call_user_func() [function.call-user-func]: First argument is expected to be a valid callback in /home/free/ic.cz/s/snw/root/www/inventory.php  on line 28
Line 28 of inventory.php
Code: [Select]
call_user_func($actions[$token]);
can u help me please ?  ???  :'(

EDIT:
it happens when i try to use (equip) the weapon

Full inventory.php in attachment
« Last Edit: May 27, 2010, 07:31:30 AM by snw »

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Inventory Error
« Reply #1 on: May 27, 2010, 08:56:24 AM »
This message is telling you that you have an invalid value that's being specified. Probably evaluates to null or something of that nature. Do this right before the line:

Code: (php) [Select]
var_dump ($actions [$token]);
exit ();

And that should show you what is being output in that segment. If it's not a valid callback then you'll know where your error is coming from.

If it is, then you need to make sure that the function that the callback refers to is defined already.

You might need some additional logic to only dump and exit under certain circumstances in case this code is used and sometimes works properly.
Idiocy - Never underestimate the power of stupid people in large groups.


Offline snw

  • Level 5
  • *
  • Posts: 15
  • Reputation: +0/-0
    • View Profile
Re: Inventory Error
« Reply #2 on: May 27, 2010, 01:16:25 PM »
ok so i did what you said and it now writes     NULL     
P.S. im a newbie in PHP  ;D

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Inventory Error
« Reply #3 on: May 27, 2010, 01:32:20 PM »
Yup, this means that the variable is not set when you're using it. I guess that I could take a look at the code whenever I get a moment. But, that's your problem in a nutshell. :) Maybe you'll figure it out before I get to it.
Idiocy - Never underestimate the power of stupid people in large groups.


Offline snw

  • Level 5
  • *
  • Posts: 15
  • Reputation: +0/-0
    • View Profile
Re: Inventory Error
« Reply #4 on: May 27, 2010, 02:39:04 PM »
ok ill try to figure it out  ;) thanks for all your help
ill write again if i fixed it

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Inventory Error
« Reply #5 on: May 27, 2010, 03:18:24 PM »
I can't track the error based upon what you have uploaded.

Try modifying the segment to look like:
Code: (php) [Select]
if($_POST) {
if($_POST['item-id']) {
$query = sprintf("SELECT item_id FROM user_items WHERE user_id = '%s' AND id = '%s'",
mysql_real_escape_string($userID),
mysql_real_escape_string($_POST['item-id']));
$result = mysql_query($query);

// make sure this is outputting a valid mysql resource
var_dump ($result);

list($itemID) = mysql_fetch_row($result);

// make sure this is set to what you expect
var_dump ($itemID);

require_once 'items.php';
$token = getItemStat('token',$itemID);

// make sure you have the right token
var_dump ($token);

// end execution
exit ();
call_user_func($actions[$token]);
}
}

This should tell you which part of the code is returning the wrong thing. From there, you can further isolate the issue.
Idiocy - Never underestimate the power of stupid people in large groups.


Offline snw

  • Level 5
  • *
  • Posts: 15
  • Reputation: +0/-0
    • View Profile
Re: Inventory Error
« Reply #6 on: May 28, 2010, 07:22:26 AM »
Code: [Select]
resource(7) of type (mysql result) string(1) "2" string(1) "0" but i dont understand this code  :-[

Offline JGadrow

  • Level 35
  • **
  • Posts: 1,133
  • Reputation: +23/-2
    • View Profile
Re: Inventory Error
« Reply #7 on: May 28, 2010, 08:35:59 AM »
Ok, your query is running properly and you're getting a valid numeric result into the $itemID variable. The issue lies within your getItemStat function. It's returning the string '0'. This means that it is trying to access
Code: [Select]
$actions [0] when you're calling a function which is not set... thus, it's trying to call the function named as the null character. Since this is an invalid function name, you get an error.

Walk through the implementation of getItemStat with the parameters: getItemStat('token', '2'); and you should be able to track down why this is returning a numeric string value.

You can get rid of the code alterations that I made now as they were strictly for diagnostic purposes. :)

*Note: var_dump() is a great function because it not only prints out the value of its argument, but the type! Basically it just told you that:

$result IS a valid resource
$itemID IS a numeric STRING (you can use intval() if you want it to be an actual integer)
$token IS the numeric STRING '0'
Idiocy - Never underestimate the power of stupid people in large groups.


 


SimplePortal 2.3.3 © 2008-2010, SimplePortal