Jump to content

[SOLVED] Keep getting an error on my search bar


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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.