-4

I am getting the following error:

Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\pictures\testingsearch.php on line 45

Could you please help to solve this error as I have tried numerous things however the error is still persistent, I believe it is my sql code that I am running prior to the while loop. The error occurs in the whileoop though.

My sql query is:

$sql = "SELECT pictures.idpic, pictures.name, pictures.info, pictag.tagpicID, pictag.pictagName, tagging.IDimage, tagging.tagpicID 
    FROM pictures, pictag, tagging
    WHERE pictures.idpic = '$searchvalueentered ' 
    OR pictag.tagpicID= '$searchvalueentered ' 
    OR tagging.tagpicID= '$searchvalueentered '";
gen_Eric
  • 223,194
  • 41
  • 299
  • 337
  • possible duplicate of [mysql\_fetch\_array() expects parameter 1 to be resource, boolean given in select](http://stackoverflow.com/questions/2973202/mysql-fetch-array-expects-parameter-1-to-be-resource-boolean-given-in-select) – John Conde Mar 26 '14 at 16:00
  • Run your query from the command line or use `mysql_error()` to get your error message – John Conde Mar 26 '14 at 16:00
  • 1
    Don't ignore the query's errors, print them. `$result = mysql_query($sql); if(!$result){ die(mysql_error()); }` – gen_Eric Mar 26 '14 at 16:05
  • @JohnConde Thanks John, I have tried to do this but still cannot figure out why my image does not get displayed on the page, it is quite tedious to figure out what is wrong as I have also changed the SQL but the error is consistent with the 'whileloop' – user3430970 Mar 26 '14 at 16:08
  • @RocketHazmat The error is still persitent with " while($row = mysql_fetch_array($result)){" which I cannot figure out what is wrong as I am running two different image searches one being based on the name of the image so when the user types the name of the image to search it comes back with the result and the other search looks at the "tags" which the image has got then the query should show these images. The query being executed does not show an image when the "tag" is being searched for? – user3430970 Mar 26 '14 at 16:14
  • Did `die(mysql_error())` show you anything? – gen_Eric Mar 26 '14 at 16:15
  • @RocketHazmat die(mysql_error()) showed me this statement - Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in C:\xampp\htdocs\picgallery\taggingsearch.php on line 45 – user3430970 Mar 26 '14 at 16:29
  • @user3430970: No, it didn't. Looks like `die(mysql_error())` wasn't even called. Can you show us your code? – gen_Eric Mar 26 '14 at 16:33
  • @RocketHazmat I may not be executing "die(mysql_error())" correctly. Yeh sure this is my code: } – user3430970 Mar 26 '14 at 16:41
  • Add `if(!$result){ die(mysql_error()); }` before the `while` loop, right after `$result = mysql_query($sql);`. – gen_Eric Mar 26 '14 at 16:44
  • @RocketHazmat I did this and when searching for an image nothing is displayed, the screen is just blank now when trying to carry out the "tag" search. When searching for the image name search, images are displayed for this. – user3430970 Mar 26 '14 at 16:58

1 Answers1

0

Put the entire code in Try catch block. It will show you please where it fails. Then debug the line.

kayra
  • 228
  • 3
  • 10
  • Thanks for this. Do you know how I can use this please? – user3430970 Mar 26 '14 at 17:02
  • Something like Try{Entire code starting from $sql=""; $result=mysql_query($sql);while loop}catch(Exception $e){echo "exception".mysql_error()."message : ".$e.getMessage();} – kayra Mar 26 '14 at 19:11