-1

Can anyone help me please. I get the error Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in...

my code:

include("../connection.php");

$con=mysql_connect($host, $username, $password, $db_name) or die ("insert error message");


mysql_select_db("db") or die ("Couldn't find database"); 

$story=mysql_query("SELECT hand_story.username, hand_story.age, hand_story.occupation,    
hand_story.star_sign, hand_story.cats_and_dogs, hand_story.holiday, hand_story.single, 
hand_story.story, big_hand_images.username, big_hand_images.url 
FROM hand_story    
INNER JOIN big_hand_images
ON hand_story.username=big_hand_images.username
WHERE big_hand_images.url='$guess'");

echo (mysql_error());

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

$age = $row['age'];
$occupation = $row['occupation'];
$star_sign = $row['star_sign'];
$cats_and_dogs = $row['cats_and_dogs'];
$holiday = $row['holiday'];
$single = $row['single'];
$story = $row['story'];
}

I can echo out the results from database, so it's working but I can't figure out why I'm getting the error message as well.

Can anyone help? Is it something to do with my SQL query? Ta

user1022772
  • 651
  • 3
  • 14
  • 29

3 Answers3

0

Try this :
WHERE big_hand_images.url='" . $guess . "'");

Watch out for mysql injections

Jordi Kroon
  • 2,607
  • 3
  • 31
  • 55
0

Anytime you get that type of error, know that there are errors in your sql query and therefore MySQL did not return rows.

Solution: copy the sql statement and run in phpmyadmin or something similar and make sure the query works there. Printing out the query will reveal what PHP is sending to MySQL

codingbiz
  • 26,179
  • 8
  • 59
  • 96
  • I tried this and it is returning a row. I am able to echo out the results as I'm getting one row returned. Sti – user1022772 Aug 23 '12 at 23:17
  • did you `echo($sql)` in your php? what does the output look like? what's the value in `$guess`? – codingbiz Aug 23 '12 at 23:20
  • Cheers. I can see what I've done now. Was using same variable name -$story. Change the name of my query to $story1 and this got rid of the error. Cheers for your help – user1022772 Aug 23 '12 at 23:27
0

I can see what I've done now.

Was using same variable name -$story. Changed the name of my query to $story1 and this got rid of the error.

user1022772
  • 651
  • 3
  • 14
  • 29