Jump to content

Archived

This topic is now archived and is closed to further replies.

crazylegseddie

Unwanted warning??

Recommended Posts

I have a search script that I have inputted at the home of my site and works correctly but with the following script:
[code]
$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 />';
    }
[/code]

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.

Share this post


Link to post
Share on other sites
add this just after the query (without die();)

echo mysql_error();

Share this post


Link to post
Share on other sites
thx for reply but i inserted the following like this:

[code]
  $result = mysql_query($sql);  echo mysql_error();
[/code]

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


Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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. :(

Share this post


Link to post
Share on other sites
Echo out your query and put it into phpMyAdmin or MySQL Query Browser and make sure that it is not a syntax error.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites

×

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.