Jump to content

[SOLVED] Problems with a MySQL Query


Glenugie

Recommended Posts

I am working on a project using PHP and MySQL, I am currently doing part which dynamically changes an image using the value in a database. I have it connect to the database, and start a session. Here is the query:

 

<?
13- $username = $_SESSION["username"];
14- $result = mysql_query("SELECT character_image FROM Users AS character_image WHERE username=$username");
15- $row = mysql_fetch_array($result);
16- $CharImage = $row['character_image'];
?>

 

I have tested that $username has a value by echoing it, and it does. It returns this error:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in htdocs\charsheet.php on line 15

 

And the location of the image it tries to access is what was entered as text, but it misses out the variable part, as the query is failing.

 

Any advice as to why the query is failing would be appreciated

 

~Glenugie~

Link to comment
Share on other sites

Rather than start a new thread, I have another problem, different query.

 

I am trying to create a simple inventory system, this inventory system is to reference an items table, which holds the names of each item, which is normally represented as an item. The inventory holds the item code, which linked by relationship to the items code. The code for the query is:

5- $result= mysql_query("SELECT Inventory.Item_Code, Items.ItemID, Items.Name FROM (Inventory INNER JOIN Items ON Inventory.Item_Code = Items.ItemID)");
6- $row = mysql_fetch_array($result);

The error returned is:

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in htdocs\inventory.php on line 6

 

It is designed to basically get the real item name from the items database from the item code in the inventory database. I think I may have my syntax slightly wrong. Any help with this second problem would of course be appreciated. Thanks.

 

~Glenugie~

Link to comment
Share on other sites

Try removing the parenthesis after the FROM.  Not sure why that would do it, but it's all I can think of.

 

 

Also, try changing

 

$result= mysql_query("SELECT Inventory.Item_Code, Items.ItemID, Items.Name FROM (Inventory INNER JOIN Items ON Inventory.Item_Code = Items.ItemID)");

 

To

 

$result= mysql_query("SELECT Inventory.Item_Code, Items.ItemID, Items.Name FROM (Inventory INNER JOIN Items ON Inventory.Item_Code = Items.ItemID)") or die(mysql_error());

 

 

(In a production environment, you would never want to use an or die() clause to check for a query error, but for dev'ing it's usually fine ;p.)

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.