Jump to content

Can't see the problem in a simple php code!


ashlegen

Recommended Posts

Hi guys.I've got a problem.I'm building my php browsergame and i'm stuck into the inventory page.I have a code that seems ok to me but it won't work.Here it is:

 

 

$inventory = array();

$query = sprintf("SELECT id, item_id, quantity FROM user_items WHERE user_id = '%s'",

mysql_real_escape_string($userID));

$result = mysql_query($query);

while($row = mysql_fetch_assoc($result)) {

$item_query = sprintf("SELECT name FROM items WHERE id = '%s'",

mysql_real_escape_string($row['item_id']));

$item_result = mysql_query($item_query);

list($row['name']) = mysql_fetch_row($item_result);

array_push($inventory,$row);

}

 

 

 

I've spotted the problem.The $inventory array is empty.I checked it with if(empty($inventory)) .Thanks in advance and keep in mind that I'm a noob yet.

No, that's a formatted string placeholder, not a wildcard operator.

 

Are you sure $userID has a valid value? Have you tried echo $query;?

 

Oh man!I checked now and i've got the poblem.You were right.$uerID never had a value because i forgot the session_start() thing at the begiing of the document.Thanks again guys and I'm looking forward to ask more here.Cheers!  :-*

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.