-
Notifications
You must be signed in to change notification settings - Fork 0
/
customer-backend-search.php
71 lines (68 loc) · 2.63 KB
/
customer-backend-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
<?php
/* Attempt MySQL server connection. Assuming you are running MySQL
server with default setting (user 'root' with no password) */
try{
$pdo = new PDO("mysql:host=localhost;dbname=fnf", "root", "");
// Set the PDO error mode to exception
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch(PDOException $e){
die("ERROR: Could not connect. " . $e->getMessage());
}
// Attempt search query execution
try{
if(isset($_REQUEST["term"])){
// create prepared statement
// $sql = "select id, first_name, last_name, phone, email from (select distinct first_name, last_name, phone, email from customers WHERE `first_name` LIKE '%s%' ) customers";
$sql = "SELECT *
FROM fnfCustomer
WHERE `firstName` LIKE :term
OR `lastName` LIKE :term
OR `phone1` LIKE :term
OR `phone2` LIKE :term
OR `email` LIKE :term
OR `billStreetNumber` LIKE :term
OR `billStreet` LIKE :term
OR `billStreetType` LIKE :term
OR `billSuburb` LIKE :term
OR `billCity` LIKE :term";
$stmt = $pdo->prepare($sql);
$term = $_REQUEST["term"] . '%';
// bind parameters to statement
$stmt->bindParam(":term", $term);
// execute the prepared statement
$stmt->execute();
if($stmt->rowCount() > 0){
while($row = $stmt->fetch()){
$id = $row['customer_ID'];
$fn = $row['firstName'];
$ln = $row['lastName'];
$phone1 = $row['phone1'];
$phone2 = $row['phone2'];
$email = $row['email'];
$billStreetNumber = $row['billStreetNumber'];
$billStreet = $row['billStreet'];
$billStreetType = $row['billStreetType'];
$billSuburb = $row['billSuburb'];
$billCity = $row['billCity'];
?>
<p>
<a href="customerView.php?id=<?php echo $id; ?>" style="text-decoration: none; color:black;"><?php echo $fn . ' ' . $ln . '<br>
<img src="images/phone1.png" width="25px" weight="25px" title="Phone 1" alt="Phone 1" />' . $phone1 . '<br>
<img src="images/phone2.png" width="25px" weight="25px" title="Phone 2" alt="Phone 2" />' . $phone2 . '<br>
<img src="images/email.png" width="25px" weight="25px" title="Email" alt="Email 2" />' . $email . '<br>
<img src="images/street.png" width="25px" weight="25px" title="Street" alt="Street" />' . $billStreetNumber . ' ' . $billStreet . ' ' . $billStreetType . ',<br>' . $billSuburb; ?></a>
</p>
<?php
}
} else{
echo "<p>No matches found</p>";
}
}
} catch(PDOException $e){
die("ERROR: Could not able to execute $sql. " . $e->getMessage());
}
// Close statement
unset($stmt);
// Close connection
unset($pdo);
?>