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.

Link to comment
Share on other sites

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!  :-*

Link to comment
Share on other sites

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.