SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Enthusiast
    Join Date
    Nov 2011
    Posts
    42
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    PHP search engine

    I'm trying to make a search engine by watching a tutorial, exactly copied every code but in the middle of the tutorial I'm stuck, The guy Alex from PHPacademy smoothly goes off, but I cant proceed for this error. Please HELP!

    Warning: mysql_fetch_assoc() expects parameter 1 to be resource, boolean given in Y:\wamp\www\SearchEngine\search.php on line 27




    Code PHP:
    <?php
     
     
    //get data
    $button = $_GET['submit'];
    $search = $_GET['search'];
     
    if (!$button)
    	echo "You didn't submit a keyword";
     
    	else
    	{
    	if (strlen($search)<=2)
    		echo "search term is too short";
    			else
    			{
    			  echo "You searched for $search<hr size='1'>";
     
     
    			//Connect to our Database
    			mysql_connect("localhost","root","");
    			mysql_select_db("searchengine") or die(mysql_error());
     
     
     
    			$get = mysql_query("SELECT * FROM 'search'");
    			while ($result = mysql_fetch_assoc($get))    <<<<----------------------LINE 27--------------------------
    			{
    				$search_exploded = explode(" ",$search);
     
     
    					foreach(search_exploded as $search_each)
    				{
    					echo $search_each."<br>";
    				}
    			}
     
     
    	}
    }
     
     
    ?>

  2. #2
    SitePoint Wizard bronze trophy
    Join Date
    Jul 2006
    Location
    Augusta, Georgia, United States
    Posts
    4,194
    Mentioned
    17 Post(s)
    Tagged
    4 Thread(s)
    Remove the quotes from around the table name on line 26.

    Though for future reference that error means the query failed.

    Also, if your searching a table it would probably be best to use a where clause and/or full text searching. Though I'm not entirely certain what your trying to achieve considering your definition of search looks to be selecting all the data in table. When mine is to limit the data in a table based on a certain set of criteria.
    The only code I hate more than my own is everyone else's.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •