-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdatabase_search.php
74 lines (61 loc) · 1.58 KB
/
database_search.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
<?php
// windows path
// php search data in mysql database using PDO
// set data in input text
$id = "";
$first_name = "";
$last_name = "";
$phone = "";
if(isset($_POST['submit']))
{
// connect to mysql
require_once(dirname(__FILE__). "\database_connect.php");
// id to search
$id = $_POST['id'];
// mysql search query
$pdoQuery = "SELECT * FROM users WHERE id = :id";
$pdoResult = $conn->prepare($pdoQuery);
//set your id to the query id
$pdoExec = $pdoResult->execute(array(":id"=>$id));
if($pdoExec)
{
// if id exist
// show data in inputs
if($pdoResult->rowCount()>0)
{
foreach($pdoResult as $row)
{
$id = $row['id'];
$fname = $row['first_name'];
$lname = $row['last_name'];
$age = $row['phone'];
}
}
// if the id not exist
// show a message and clear inputs
else{
echo 'No Data With This ID';
}
}else{
echo 'ERROR Data Not Inserted';
}
}
?>
<html>
<head>
<title>Search by Names | Email | Phone Numbers</title>
</head>
<body>
<form action="php_search_in_mysql_database_using_pdo.php" method="post">
ID:<br/>
<input type="text" name="id" value=""><br/>
First Name:<br/>
<input type="text" name="first_name" value=""><br/>
Last Name:<br/>
<input type="text" name="last_name" value=""><br/>
Phone Number:<br/>
<input type="text" name="phone" value=""><br/>
<input type="submit" name="submit" value="Search">
</form>
</body>
</html>