How does this look? I am escaping the GET data before the SQL query and I am stripping the slashes for the display search word so it looks just as the user typed it:
PHP Code:<?php
dbConnect();
$original_search_word = $_GET['search'];
$search_word = mysql_real_escape_string($original_search_word);
?>
<form name='search' method='get' action='".$_SERVER['PHP_SELF']."'>
<input name='search' id='search'/>
<input type='submit' value='Search' name='submit'/>
</form>
<?php
if(array_key_exists("submit", $_GET)){
echo "Your search for: <strong>".stripslashes($original_search_word)."</strong><p>
<ol>
";
$sql = 'SELECT * FROM table WHERE name LIKE "%'.$search_word.'%"';
$result = mysql_query($sql) or die(mysql_error());
$num = mysql_num_rows($result);
while($row = mysql_fetch_assoc($result)){
$name = $row['name'];
echo "<li>$name</li>";
}
echo "</ol>";
}
?>






Bookmarks