-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprotected_app.php
More file actions
executable file
·50 lines (45 loc) · 1.25 KB
/
Copy pathprotected_app.php
File metadata and controls
executable file
·50 lines (45 loc) · 1.25 KB
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
<!DOCTYPE html>
<html>
<head>
<title>Hardware Store</title>
<meta charset="utf-8">
</head>
<body>
<h1>Katie's Hardware</h1>
<form action="" method="GET">
<input type="text" name="search">
<input type="submit" name="submit" value="Search">
</form>
<?php
if (isset($_GET['search'])) {
$host = "localhost";
$db = "hardware_store";
$user = "root";
$pwd = "ch@ng3dt00r";
try {
$conn = new PDO("mysql:host=$host;dbname=$db", $user, $pwd);
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$item = $_GET['search'];
$stmt = $conn->prepare("SELECT * FROM products WHERE name LIKE :item");
$stmt->bindParam(':item', $item);
$stmt->execute();
$results = $stmt->fetchAll(PDO::FETCH_ASSOC);
echo '<table class="table table-striped table-bordered table-hover">';
echo "<tr><th>Name</th><th>Description</th><th>Cost</th><th>Availability</th></tr>";
foreach($results as $row) {
echo "<tr>";
echo "<td>".$row['name']."</td>";
echo "<td>".$row['description']."</td>";
echo "<td>".$row['price']."</td>";
echo "<td>".$row['availability']."</td>";
echo "</tr>";
}
echo "</table>";
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
}
?>
</body>
</html>