code to paste:
formsearch.html
<html>
<body>
<table border="1" align="center">
<form action="formsearch.php" method="post">
<tr>
<td>Marina Number:</td>
<td><input type="text" name="lastname" maxlength="7" /></td>
</tr>
<tr>
<td><input type="submit" value="search data"/></td>
<td> </td>
</tr>
</form>
</table>
</body>
</html>
formsearch.php
$con = mysql_connect("localhost","root","yourpassword");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("sample", $con);
$search=$_POST['lastname'];
$result = mysql_query("SELECT * FROM table1 where lastname='$search'");
$count=mysql_num_rows($result);
// If result matched $myusername and $mypassword, table row must be 1 row
if($count==1)
{
echo "<table border='1'>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>";
while($row = mysql_fetch_array($result))
{
echo "<tr>";
echo "<td>" . $row['lastname'] . "</td>";
echo "<td>" . $row['firstname'] . "</td>";
echo "</tr>";
}
echo "</table>";
}
else
{
echo "record not found";
}
mysql_close($con);
?>
No comments:
Post a Comment