-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstore_items.php
More file actions
22 lines (21 loc) · 858 Bytes
/
store_items.php
File metadata and controls
22 lines (21 loc) · 858 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
<HTML><HEAD>
<style> table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px; }
tr:nth-child(even)
{ background-color: Lightgreen; }</style>
</HEAD>
<BODY><h1>Welcome to Ontario Computers!</h1>
<table><tr><th>Item #</th><th>Name</th><th>Description</th><th>Price</th></tr>
<?PHP
$search = isset($_GET['search'])?" WHERE item_name LIKE ('%".$_GET['search']."%')":"";
$dsn = 'mysql:dbname=ontario_computers;host=localhost';
$dbUser = 'appuser';
$password = 'Testing!';
$db = new PDO($dsn,$dbUser,$password);
$query_string = "SELECT * FROM items".$search;
print($query_string);
$cursor = $db->query($query_string);
while ( $data = $cursor->fetchObject() ) {
printf("<tr><td>%d</td><td>%s</td><td>%s</td><td>%.2f</td></tr>",$data->item_id,$data->item_name,$data->item_description,$data->price);
}
?></table></BODY></HTML>