Version: search1.0
Type: Full Script
Category: Other
License: GNU General Public License
Description: This is a search form in php.It searches the data from mysql.
<html> <head> <title>Search Test</title> </head> <body topmargin="0" leftmargin="0"> <form action="" method="post"> Search Term <input type="text" name="search"><br /> <input type="submit" value="Search" name="Search"> </form> </body> </html> <?php if($_POST["search"]=="") { echo "please enter some text for search!"; } else { $q=$_POST["search"]; $con = mysql_connect('localhost', 'root', ''); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("key", $con); $sql="SELECT * FROM contact WHERE fname like '".$q."%'"; $result = mysql_query($sql); if(!mysql_num_rows($result)>0) { echo "Not found!"; } else { echo "<table border='1'> <tr> <th>Firstname</th> </tr>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>" . $row['fname'] . "</td>"; echo "</tr>"; } echo "</table>"; }} ?>