Here you can find the code please click below
DEMO
Form.php
<!DOCTYPE html>
<html dir="ltr" lang="en-US" >
<head>
<meta charset="UTF-8" />
<title>Search</title>
</head>
<body>
<h>search by name</h>
<form action="search.php" method="get">
<label>Name:
<input type="text" name="name" />
</label>
<input type="submit" value="Search" />
</form>
</body>
</html>
Search.php
<?php
$searchTerm = trim($_GET['name']);
if($searchTerm == "")
{
echo "Enter name ";
exit();
}
//database connection info
$host = "localhost";
$db = "dbname";
$user = "root";
$pwd = "ubuntu@rituraj";
$link = mysqli_connect($host, $user, $pwd, $db);
$query = "SELECT * FROM student WHERE name LIKE '%$searchTerm%'";
$results = mysqli_query($link, $query);
if(mysqli_num_rows($results) >= 1)
{
$output = "";
while($row = mysqli_fetch_array($results))
{
$output .= "ID: " . $row['id'] . "<br />";
$output .= "Name: " . $row['name'] . "<br />";
$output .= "Course: " . $row['course'] . "<br />";
$output .= "Age: " . $row['age'] . "<br /><br />";
}
echo $output;
}
else
echo "No record Found for Name " . $searchTerm;
?>
Database
dbname (database name)
student (table name)
id
|
name
|
course
|
age
|
1
|
Rituraj kumar
|
B.Tech
|
23
|
2
|
Robi tomar
|
Android
|
24
|
3
|
Shikha chaudhary
|
Asp.Net
|
23
|
4
|
Harshu
|
SEO
|
21
|
5
|
Neeraj
|
UI Developer
|
23
|
No comments:
Post a Comment