-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
56 lines (40 loc) · 1.55 KB
/
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
<?php
require_once "classes/DBAccess.php";
$title = "Product Search";
$pageHeading = "Product Search";
//get database settings
include "settings/db.php";
//create database object
$db = new DBAccess($dsn, $username, $password);
//connect to database
$pdo = $db->connect();
$sql = "select categoryName, categoryId from category";
$stmt = $pdo->prepare($sql);
$rows = $db->executeSQL($stmt);
//start buffer
ob_start();
//display the search form
// include "templates/searchForm.html.php";
//check if the search button has been pressed
if (isset($_GET["submitButton"]) && isset($_GET["search"]))
{
$search = $_GET["search"];
$dsn = "mysql:host=localhost;dbname=SportsWH;charset=utf8";
$username = "root";
$password = "";
//create database object
$db = new DBAccess($dsn, $username, $password);
//connect to database
$pdo = $db->connect();
//set up query to execute search word including before and after hence %xx%
$sql = "select photo, price, salePrice, itemName, itemId, CategoryId from item where ItemName like :itemName";
$stmt = $pdo->prepare($sql);
$stmt->bindValue(":itemName", "%$search%");
//execute SQL query
$rowsProducts = $db->executeSQL($stmt);
//display products
include "templates/productCard.html.php";
}
$output = ob_get_clean();
include "templates/layoutSearch.html.php";
?>