-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathproduct.php
62 lines (56 loc) · 2.42 KB
/
product.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
57
58
59
60
61
62
<!DOCTYPE html>
<html>
<head>
<title>Product Page</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
</head>
<body>
<div class="container mt-5">
<h1 class="text-center">Product Details</h1>
<div class="row justify-content-center"> <!-- Use 'justify-content-center' to center the content -->
<?php
// Check if a specific product ID is set
if (isset($_GET['id'])) {
// Connect to the database
$servername = 'localhost';
$username = 'root';
$password = '';
$dbname = 'shop';
$conn = mysqli_connect($servername, $username, $password, $dbname);
if (!$conn) {
die("Failed to connect to the database: " . mysqli_connect_error());
}
$product_id = $_GET['id'];
// SQL query to retrieve product details
$sql = "SELECT * FROM products WHERE id = $product_id";
$result = mysqli_query($conn, $sql);
if (mysqli_num_rows($result) > 0) {
$row = mysqli_fetch_assoc($result);
?>
<div class="col-md-4">
<div class="card mx-auto"> <!-- Use 'mx-auto' for centering -->
<img src="<?php echo $row['image_path']; ?>" alt="<?php echo $row['name']; ?>" class="card-img-top">
<div class="card-body">
<h5 class="card-title"><?php echo $row['name']; ?></h5>
<p class="card-text">Price: <?php echo $row['price']; ?> SAR</p>
<p class="card-text">Description: <?php echo $row['description']; ?></p>
</div>
</div>
</div>
<?php
} else {
echo "Product not found.";
}
// Close the database connection
mysqli_close($conn);
} else {
echo "Product ID not specified.";
}
?>
</div>
<div class="text-center mt-3">
<a href="Home.php" class="btn btn-primary">Back to Home Page</a>
</div>
</div>
</body>
</html>