I do a search on PHP, but it does not work. Crawl error

Warning: mysql_fetch_array () expects parameter 1 to be resource, boolean given in

Code:

$news = mysql_query("SELECT * FROM news WHERE MATCH (name, text1, text2) AGAINST (`$search` IN BOOLEAN MODE)",$connect); $rownews = mysql_fetch_array($news); 

Structure:

 CREATE TABLE IF NOT EXISTS `news` ( `id` int(6) NOT NULL AUTO_INCREMENT, `name` varchar(255) NOT NULL, `cat` int(4) NOT NULL, `rating` int(11) NOT NULL, `img` varchar(255) NOT NULL, `text1` text NOT NULL, `text2` text NOT NULL, `date` varchar(20) NOT NULL, PRIMARY KEY (`id`), FULLTEXT KEY `text2` (`text2`), FULLTEXT KEY `text1` (`text1`), FULLTEXT KEY `name` (`name`) ) ENGINE=MyISAM DEFAULT CHARSET=cp1251 AUTO_INCREMENT=17 ; 

Reported as a duplicate by Athari , Yura Ivanov , Maxim Kamalov , ixSci , AntonioK May 16 '15 at 6:05 .

A similar question was asked earlier and an answer has already been received. If the answers provided are not exhaustive, please ask a new question .

    5 answers 5

    The case is in quotes, more correctly

     $news = mysql_query("SELECT * FROM news WHERE MATCH (name, text1, text2) AGAINST ('$search' IN BOOLEAN MODE)",$connect); if (is_bool($news)) { // или можно $news === FALSE die "Mysql (".mysql_errno($connect).") ".mysql_error($connect)."\n"; } else { $rownews = mysql_fetch_array($news); // Что там нужно будет делать дальше } 

      mysql_query() returns FALSE on error. And you pass this FALSE to mysql_fetch_array() .

      Find the error in the query and add a check on FALSE before mysql_fetch_array

        Just write before the query: echo mysql_error (); there everything will show

          Remove from the WHERE query, at least it helped me!

          • ERROR 1064 (42000): You have an error in your SQL syntax; For example, the syntax for the use of the syntax for the use of the syntax for the use of the AGC ("XXX" IN BOOLEAN MODE) "at line 1 - chernomyrdin

          After AGAINST, parentheses are what you need. Take it away.

          • ERROR 1064 (42000): You have an error in your SQL syntax; If you want to go back to the right place, you must have the AGHAINST 'xxx' IN BOOLEAN MODE 'at line 1 according to the dock dev.mysql.com/doc/refman/5.5 / en / ... brackets are required - chernomyrdin