PHP Code to Search A Record from Database

PHP Code to Search A Record from Database

Welcome to all to view and download free code of PHP to Search A Record from Database.
If you have further query, join our facebook page. Click here to join.

FREE CODE DOWNLOAD

File name:

search.php

<?
include_once(“checkSession.php”);
include_once(“connect2.php”); //start of search
$a1=$_REQUEST[‘a1’];
$findValue=$_POST[‘findValue’];
if ($a1==”Search”) {
$sql=”SELECT * FROM student where Name like ‘$findValue%’ order by StudentID ASC”;

if(!$q=mysql_query($sql)){
echo mysql_error();
}
elseif(mysql_num_rows($q)==0) {
echo “No Student Name exists”;
}
else{
$tsql=”SELECT FOUND_ROWS() as found”;
$qq=mysql_query($tsql);
$rr=mysql_fetch_object($qq);
$found_rows=$rr->found;
$display_result=true;
}
}
?>

<html>
<head>
<title> PHP Search Data Form </title>
</head>
<body bgcolor=”#CCCCFF” text=”#330099″>
<form method=”post” name=”a1″ action=”search.php”>
<h1 align=”center”><font face=”Verdana”><b>Search Student Form</b></font></h1>
<table align=”center”>
<tr>
<td>
Name: <input name=”findValue” value=”<?=$findValue;?>” size=”30″>
</td>
</tr>
<tr>
<td align=”right”>
<input type=”submit” name=”a1″ align=”center” value=”Search” />
<input type=”hidden” name=”studentid” />
</td>
</tr>
<tr>
<td>
<a href=”main.php”>Back to Main Page</a>
</td>
</tr>
</table>
</form>

<?
if($display_result) {
?>
<br/><br/>
<h1 align=”center”><font face=”Verdana”><b>Search Student Result</b></font></h1>
<br/>
<h3 align=”center”><font face=”Verdana”><b>Entries Found: <?=$found_rows;?></b></font></h3>
<table align=”center” cellpadding=”2″ cellspacing=”0″ border=”1″ >
<tr>
<td align= “center” width=”100″>
<font face= “verdana” color=”black” size=”2″>
<big><strong>
Student ID
</strong></big>
</font>
</td>
<td align=”center”>
<font face= “verdana” color=”black” size=”2″>
<big><strong>
Name
</strong></big>
</font>
</td>
<td align= “center” width=”70″>
<font face= “verdana” color=”black” size=”2″>
<big><strong>
Course
</strong></big>
</font>
</td>
<td align= “center” width=”70″>
<font face= “verdana” color=”black” size=”2″>
<big><strong>
Yr/Sec
</strong></big>
</font>
</td>
<td align= “center” width=”70″>
<font face= “verdana” color=”black” size=”2″>
<big><strong>
Edit
</strong></big>
</font>
</td>
<td align= “center” width=”70″>
<font face= “verdana” color=”black” size=”2″>
<big><strong>
Delete
</strong></big>
</font>
</td>
</tr>
<?
while ($rs=mysql_fetch_object($q)){
?>
<tr>
<td align=”center”>
<font face= “times new roman” color=”black”>
<b>
<?=$rs->StudentID;?>
</b>
</font>
</td>
<td>
<font face= “times new roman” color=”black”>
<b>
<?=$rs->Name;?>
</b>
</font>
</td>
<td align=’center’>
<font face= “times new roman” color=”black”>
<b>
<?=$rs->Course;?>
</b>
</font>
</td>
<td align=’center’>
<font face= “times new roman” color=”black”>
<b>
<?=$rs->YrSec;?>
</b>
</font>
</td>
<td align=’center’>
<a href=”editform.php?studentid=<?=$rs->StudentID;?>”>Edit</a>
</td>
<td align=’center’>
<a href=”delete.php?action=del&studentid=<?=$rs->StudentID;?>”>Delete</a>
</td>
</tr>
<?
}
?>
<?/*
while ($r=mysql_fetch_object($q)) {
echo “<tr>
<td align=’center’>
<font face=’arial’ color=’black’ size=’2′><b>$r->Name</b></font>
</td>
</tr>”;
}
*/
?>
</table>
<?
}
?>

</body>
</html>

File name:

haris.css

 

Leave a Reply

Your email address will not be published. Required fields are marked *