Jump to content

[SOLVED] Keep getting an error on my search bar


Ner0

Recommended Posts

This is the input code for my search bar

<form id="search" name="search" method="post" action="search.php"> 
  <fieldset id="search">  
    <label id="search">Search for games
      <input type="text" name="search" id="search"></input> 
      </label>
      </form>
      </fieldset>

This is the search.php file

<?php
if( $_POST['search'] )
{
   mysql_pconnect("localhost","root","") or die("ERROR: Could not connect to database!");
   mysql_select_db("games");
   $search = addslashes( $_POST['search'] );
   $result = mysql_query(" SELECT games.Name2 FROM games WHERE Name2 = \"$search\" ORDER BY occurrences DESC ");
   print "<h2>Search results for '".$_POST['search']."':</h2>\n";
   for( $i = 1; $row = mysql_fetch_array($result); $i++ )
   {
      print "$i. <a href='".$row['Link']."'>".$row['Name2']."</a>\n";
   }
}
?>

This is the error I keep recieving

Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in C:\wamp\www\search.php on line 9

The database is called games, the table is called games and the field im searching is called Name2.

 

Any help in getting rid of this error and getting the search bar working would be appreciated.

 

That means $result isn't a valid mysql result resource, or in other words

mysql_query(" SELECT games.Name2 FROM games WHERE Name2 = \"$search\" ORDER BY occurrences DESC ");

failed.

 

Place a

echo mysql_error();

just after you run that query and it will you give the reason why its failing.

Archived

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

×
×
  • Create New...

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.