Jump to content


Photo

Unwanted warning??


  • Please log in to reply
7 replies to this topic

#1 crazylegseddie

crazylegseddie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 August 2006 - 12:12 PM

I have a search script that I have inputted at the home of my site and works correctly but with the following script:
 $sql = "SELECT pd_id, pd_name, pd_more, pd_more2,  
               MATCH(pd_name, pd_more, pd_more2)  
               AGAINST ('$searchstring' IN BOOLEAN MODE) FROM tbl_product
               WHERE MATCH(pd_name, pd_more, pd_more2)  
               AGAINST ('$searchstring' IN BOOLEAN MODE) ORDER BY pd_name DESC"; 
     }    
     $result = mysql_query($sql) or die (mysql_error()); 
	   
   while($row = mysql_fetch_assoc($result)) 
    { 
      echo "<a href='categories.php?c=0&p=". $row['pd_id']. "'>".stripslashes(htmlspecialchars($row['pd_name'])).'</a><br />'; 
    } 

A message saying 'query is empy' is displayed and cancels the rest of my html page. But if i remove 'or die (mysql_error());' then i get the following warning.

'Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result' but the rest of the page now loads correctly.

How do i overcome this problem im having?

Any help will be cool.



#2 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 20 August 2006 - 12:17 PM

add this just after the query (without die();)

echo mysql_error();
Tell me the problem, I will try tell you the solution

#3 crazylegseddie

crazylegseddie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 August 2006 - 12:37 PM

thx for reply but i inserted the following like this:

   $result = mysql_query($sql);  echo mysql_error();

and recieved both unwanted comments:
'Query was empty
Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result'




#4 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 20 August 2006 - 01:35 PM

It most likely means that your mysql connection is failing.  Add the "or die(mysql_error());" to the end of your mysql_connect and any other db functions above the code you provided.

#5 crazylegseddie

crazylegseddie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 August 2006 - 01:51 PM

it is definately not the connection as I have the connection stored in a config file and is functional over the rest of my site. If I add 'die(mysql_error());' then I just receive 'Query was empty' and the rest of the page after the php script does not load. :(

#6 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 20 August 2006 - 01:57 PM

Echo out your query and put it into phpMyAdmin or MySQL Query Browser and make sure that it is not a syntax error.

#7 crazylegseddie

crazylegseddie
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 20 August 2006 - 03:37 PM

it was a bit of unused script that was causing the problem. I removed it and now everything runs fine :)

#8 onlyican

onlyican
  • Members
  • PipPipPip
  • Advanced Member
  • 921 posts
  • LocationHants - UK

Posted 20 August 2006 - 06:24 PM

the query is empty, normally means there is no query
$query = "SELECT * FROM table";
$result = mysql_query($query2);
//Note the 2 after the mysql_query

This will respond with the query is empty, as $query2 does not exsists
Tell me the problem, I will try tell you the solution




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users