-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathViewOrderDetails.php
More file actions
60 lines (51 loc) · 1.94 KB
/
Copy pathViewOrderDetails.php
File metadata and controls
60 lines (51 loc) · 1.94 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
51
52
53
54
55
56
57
58
59
60
<?php
include_once('./functions.php');
// did the user provided an OrderID via the URL?
if (isset($_GET['OrderID'])) {
$UnsafeOrderID = $_GET['OrderID'];
$dbh = connectToDatabase();
// select the order details and customer details. (you need to use an INNER JOIN)
// but only show the row WHERE the OrderID is equal to $UnsafeOrderID.
$statement = $dbh->prepare('
SELECT *
FROM Orders
INNER JOIN Customers ON Customers.CustomerID = Orders.CustomerID
WHERE OrderID = ? ;
');
$statement->bindValue(1, $UnsafeOrderID);
$statement->execute();
// did we get any results?
if ($row1 = $statement->fetch(PDO::FETCH_ASSOC)) {
// Output the Order Details.
$FirstName = makeOutputSafe($row1['FirstName']);
$LastName = makeOutputSafe($row1['LastName']);
$OrderID = makeOutputSafe($row1['OrderID']);
$UserName = makeOutputSafe($row1['UserName']);
// TODO: select all the products that are in this order (you need to use INNER JOIN)
// this will involve three tables: OrderProducts, Products and Brands.
$statement2 = $dbh->prepare('
SELECT * FROM Orders AS O
INNER JOIN OrderProducts AS OP ON O.OrderID = OP.OrderID
INNER JOIN Products AS P ON P.ProductID = OP.ProductID
INNER JOIN Brands AS B ON P.BrandID = B.BrandID
INNER JOIN Customers AS C ON O.CustomerID = C.CustomerID
WHERE O.OrderID = ? ;
');
$statement2->bindValue(1, $UnsafeOrderID);
$statement2->execute();
$rows = $statement2->fetchAll(PDO::FETCH_ASSOC);
include("./views/partials/navbar.php");
include("./views/partials/head.php");
$heading = "Order Details";
$bannerMessage = "Showing the details of the order.";
// $marqueeDuration = 9;
include("./views/partials/banner.php");
include "./views/ViewOrderDetails.view.php";
} else {
include "./views/partials/head.php";
include "./views/Error.view.php";
}
} else {
include "./views/partials/head.php";
include "./views/Error.view.php";
}