*
<?php
mysql_connect("localhost","root","") or die ("could not connect");
mysql_select_db("search_test") or die ("could not find db!");
//collect
if(isset($_POST['search'])){
$searchq = $_POST['search'];
$searchq = preg_replace("#[^0-9a-z]#i","",$searchq);
$query = mysql_query("SELECT * FROM members WHERE firstname LIKE '%$searchq%' OR lastname LIKE '%$searchq%'") or die ("could not search!");
$count = mysql_num_rows($query);
if ($count == 0 ) {
$output = 'There was no search results!';
}else{
while($row = mysql_fetch_array ($query)) {
$fname = $row ['firstname'];
$lname = $row ['lastname'];
$id = $row ['ID'];
$output .='<div>'.$fname.' '.$lname.' </div>';
}
}
}
print $output = ""; ?> <html> <head> <meta http-equiv="content-Type" content="txt/html; charset=utf=8" /> <title>Search</title> </head> <body> <form action="index.php" method="post"> <input type="test" name="search" placeholder="Search for members..."> <input type="submit" value="GO" /> </form> </body> </html>
*