Ner0 Posted July 25, 2009 Share Posted July 25, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/167401-solved-keep-getting-an-error-on-my-search-bar/ Share on other sites More sharing options...
Philip Posted July 25, 2009 Share Posted July 25, 2009 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. Quote Link to comment https://forums.phpfreaks.com/topic/167401-solved-keep-getting-an-error-on-my-search-bar/#findComment-882730 Share on other sites More sharing options...
Ner0 Posted July 25, 2009 Author Share Posted July 25, 2009 Thanks issue resolved Quote Link to comment https://forums.phpfreaks.com/topic/167401-solved-keep-getting-an-error-on-my-search-bar/#findComment-882734 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.