-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcar.php
More file actions
86 lines (78 loc) · 3.48 KB
/
car.php
File metadata and controls
86 lines (78 loc) · 3.48 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
<!DOCTYPE html>
<html lang="en">
<head>
<?php include "./includes/bootstrap-header.php" ?>
<link rel="stylesheet" href="./css/cars.css">
</head>
<body>
<?php include "./includes/nav.php" ?>
<?php
$car = $_GET['id'];
helloDb();
function helloDb() {
global $car;
$config = parse_ini_file('../../private/db-config.ini');
$conn = new mysqli($config['servername'], $config['username'], $config['password'], "project1004");
if ($conn->connect_error) {
$errorMsg = "Connection failed: " . $conn->connect_error;
echo $errorMsg;
$success = false;
} else {
$stmt = $conn->prepare("SELECT * FROM car WHERE id=?");
$stmt->bind_param("i", $car);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
if ($result->num_rows > 0) {
?>
<div class="header-blue" style="margin-top:65px; min-height:800px; background: url(images/hd/<?php echo $row['media']?>);">
<div class="container hero">
<div class="row">
<div class="col-12 col-lg-6 col-xl-5 offset-xl-1" style="background: rgba(0,0,0,0.25);">
<h1><?php echo $row["model"]; ?></h1>
<p><?php echo $row['description']; ?></p>
<form action="additem.php" method="post">
<p><?php
if ($row['stock'] > 0) {?>
There are stock: <?php echo $row['stock']; ?>
<?php } else { ?>
There is no stock
<?php }
?>
</p>
<p>Price is <?php echo "$" . $row['price']; ?></p>
<select id="qty" name="qty">
<?php
for ($x = 1; $x <= $row['stock']; $x++) {
echo '<option value="' . $x . '"><p>' . $x . '</p></option>';
}
?>
</select>
<input type="text" name="carid" value="<?php echo $row["id"]; ?>" hidden>
<button class="btn btn-light btn-lg action-button" type="submit">Add to Cart</button>
<br>
<br>
<br>
</div>
</form>
<div class="col-md-5 col-lg-5 offset-lg-1 offset-xl-0 d-none d-lg-block phone-holder">
<div class="phone-mockup">
<div class="screen"></div>
</div>
</div>
</div>
</div>
</div>
<?php
} else {
echo "<h1>There is no car</h1>";
}
$stmt->close();
}
}
?>
<?php
include "./includes/footer.php";
?>
</body>
</html>