Practical 21 : Write a PHP program for search record from the Database
<html>
<head>
<title>Practical : 21
</head>
<body>
<?php
mysql_connect("localhost","root","");
mysql_select_db("Class_DB");
$sno="";
$sname="";
$sadd="";
if(isset($_POST['search']))
{
$sno=$_POST['sno'];
$sql="select * from Student where sno = ".$sno;
$result=mysql_query($sql);
$row=mysql_fetch_array($result);
if($row>0)
{
$msg = "Record Found";
$sno = $row['0'];
$sname = $row['1'];
$sadd = $row['2'];
}
else
{
$msg = "Record Not Found";
}
}
?>
<center>
<form name="f1" method="post">
<table border="0px">
<tr>
<td>Sno. : </td>
<td><input type="text" name="sno" value="<?php echo $sno; ?>"></td>
</tr>
<tr>
<td>Student Name : </td>
<td><input type="text" name="sname" value="<?php echo $sname; ?>"></td>
</tr>
<tr>
<td>Address : </td>
<td>
<textarea name="sadd" cols="15" rows="3">
<?php echo $sadd; ?>
</textarea>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<b><?php echo $msg; ?></b>
</td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" name="search" value="Search">
<input type="reset" name="reset" value="Reset">
</td>
</tr>
</table>
</center>
</form>
</body>
</html>

EmoticonEmoticon