ki Posted December 29, 2006 Share Posted December 29, 2006 Okay, well I know the search result I have this code, but nothing comes up when i know there are posts in which it contains, say take a look and tell me whats wrong here.[code]if(isset($HTTP_POST_VARS['submit'])) {if(!$_POST['search']) {header("Location: ?page=forum&sub=search");die();}$searchterm = $_POST['search'];$query = mysql_query("SELECT * FROM `forum_threads` WHERE `text` LIKE %$searchterm%");while($search = mysql_fetch_object($query)) {echo $search->id;}} else {echo "<form method=\"POST\" action=\"?page=forum&sub=search\">";echo "<input type=\"text\" name=\"search\" id=\"search\">";echo "<input type=\"submit\" name=\"submit\" id=\"submit\">";echo "</form>";}[/code] Quote Link to comment Share on other sites More sharing options...
marcus Posted December 29, 2006 Share Posted December 29, 2006 [code]if(isset($_POST['submit'])) { if(!isset($_POST['search'])) { header("Location: ?page=forum&sub=search"); die(); }else { $searchterm = $_POST['search']; $query = mysql_query("SELECT * FROM `forum_threads` WHERE `text` LIKE %$searchterm%"); while($search = mysql_fetch_object($query)) { echo $search->id; } mysql_free_result($query) }} else {echo "<form method=\"POST\" action=\"?page=forum&sub=search\">";echo "<input type=\"text\" name=\"search\" id=\"search\">";echo "<input type=\"submit\" name=\"submit\" id=\"submit\">";echo "</form>";}[/code] Quote Link to comment Share on other sites More sharing options...
ki Posted December 29, 2006 Author Share Posted December 29, 2006 thanks for the response but i get this errorWarning: mysql_fetch_object(): supplied argument is not a valid MySQL result resource in /home/tragical/public_html/index.php on line 422Warning: mysql_free_result(): supplied argument is not a valid MySQL result resource in /home/tragical/public_html/index.php on line 425 Quote Link to comment Share on other sites More sharing options...
corbin Posted December 29, 2006 Share Posted December 29, 2006 try[code] $query = mysql_query("SELECT * FROM `forum_threads` WHERE `text` LIKE '%{$searchterm}%'");[/code]Oh and if you plan to publicly use this, I highly suggest you at the least addslashes() the POST input, if your server doesn't do it automatically. Quote Link to comment Share on other sites More sharing options...
ki Posted December 29, 2006 Author Share Posted December 29, 2006 Thanks corbin that worked fine, and addlsashes is auto. Quote Link to comment Share on other sites More sharing options...
corbin Posted December 29, 2006 Share Posted December 29, 2006 Glad it worked, and was just making sure on the slashes thing :p. Quote Link to comment 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.