-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsearch2.php
77 lines (61 loc) · 1.71 KB
/
search2.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!DOCTYPE html>
<html>
<head>
<title> Searching </title>
<style type="text/css">
table
{ background-color: #FCF; }
th
{
width: 150px;
text-align: left;
}
</style>
</head>
<body>
<h1>User Search</h1>
<form method="post" action="search2.php">
<input type="hidden" name="submitted" value="true"/>
<label> Search category:
<select name="category">
<option value="first_name"> first_name</option>
<option value="blood_group"> blood_group</option>
<option value="mobile_no"> mobile_no</option>
<option value="birth_date"> birth_date</option>
<option value="gender"> gender</option>
</select>
</label>
<label> Search Criteria: <input type="text" name="criteria"> </label>
<input type="submit" value="search now" />
</form>
<?php
if (isset($_POST['submitted']))
{ //connect to database
include("connectmysqlsearch.php");
$category = $_POST['category'];
$criteria = $_POST['criteria'];
$query = "SELECT * FROM personal_details WHERE $category LIKE '%".$criteria."%'";
$result = mysqli_query($dbcon, $query) or die("error retriving data");
$num_rows = mysqli_num_rows($result);
echo "$num_rows results found";
echo "<table>";
echo "<tr> <th>first_name</th> <th>blood_group</th> <th>mobile_no</th> <th>birth_date</th> <th>gender</th> </tr>";
while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
{
echo "<tr><td>";
echo $row['first_name'];
echo "</td><td>";
echo $row['blood_group'];
echo "</td><td>";
echo $row['mobile_no'];
echo "</td><td>";
echo $row['birth_date'];
echo "</td><td>";
echo $row['gender'];
echo "</td></tr>";
}
echo "</table>";
}
?>
</body>
</html>