-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdesc.php
More file actions
108 lines (95 loc) · 3.98 KB
/
desc.php
File metadata and controls
108 lines (95 loc) · 3.98 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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<?php
session_start();
include_once('header.php');
include('hms/include/config.php');
if (isset($_GET['id'])) {
$product_id = mysqli_real_escape_string($con, $_GET['id']);
$sql = mysqli_query($con, "SELECT * FROM product WHERE id='$product_id'");
$row = mysqli_fetch_assoc($sql);
if ($row):
$mrp = (float)$row['proprice'];
$discounted = (float)$row['prodiscount'];
$savings = $mrp - $discounted;
?>
<div class="container mt-5">
<div class="row">
<!-- Product Image -->
<div class="col-md-6">
<img src="hms/images/<?= htmlspecialchars($row['proimg']) ?>" alt="Product Image" class="img-fluid" style="max-height: 400px;">
</div>
<!-- Product Info -->
<div class="col-md-6">
<h1><?= htmlspecialchars($row['proname']) ?></h1>
<p><strong style="color:red;">Actual Price:</strong> <del>Rs. <?= number_format($mrp, 2) ?></del></p>
<p><strong style="color:green;">Discounted Price:</strong> Rs. <?= number_format($discounted, 2) ?></p>
<p><strong style="color:blue;">You Save:</strong> Rs. <?= number_format($savings, 2) ?></p>
<p><?= nl2br(htmlspecialchars($row['prodesc'])) ?></p>
<p><strong>Rental Price:</strong> $100 per day</p>
<p><strong>Availability:</strong> In stock</p>
<!-- Add to cart form -->
<form class="form-submit">
<input type="hidden" class="pname" value="<?= htmlspecialchars($row['proname']) ?>">
<input type="hidden" class="pprice" value="<?= $mrp ?>">
<input type="hidden" class="pdiscount" value="<?= $discounted ?>">
<input type="hidden" class="pimage" value="<?= htmlspecialchars($row['proimg']) ?>">
<input type="hidden" class="pcode" value="<?= htmlspecialchars($row['id']) ?>">
<button type="submit" id="addItem" class="btn btn-success" style="background-color:pink; font-weight:bold; color:black;">Add To Cart</button>
<div class="alert-message mt-2"></div>
</form>
</div>
</div>
</div>
<?php
else:
echo '<div class="container mt-5"><p>Product not found.</p></div>';
endif;
} else {
echo '<div class="container mt-5"><p>No product selected.</p></div>';
}
?>
<!-- JavaScript for cart functionality -->
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
<script>
$(document).ready(function() {
// Add to cart
$(document).on('click', '#addItem', function(e) {
e.preventDefault();
var form = $(this).closest(".form-submit");
var pcode = form.find('.pcode').val();
var pname = form.find('.pname').val();
var pimage = form.find('.pimage').val();
var pprice = form.find('.pprice').val(); // MRP
var pdiscount = form.find('.pdiscount').val(); // Discounted
var alertmsg = form.find('.alert-message');
$.ajax({
url: 'action.php',
method: 'POST',
data: {
pcode: pcode,
pname: pname,
pimage: pimage,
pprice: pprice,
pdiscount: pdiscount
},
success: function(response) {
alertmsg.html(response).fadeIn().delay(2000).fadeOut();
load_cart_item_number();
}
});
});
// Load cart item count
function load_cart_item_number() {
$.ajax({
url: 'action.php',
method: 'GET',
data: { cartItem: "cart_item" },
success: function(response) {
$("#cart-item").html(response);
}
});
}
load_cart_item_number();
});
</script>
<?php include_once('footer.php'); ?>
<!-- desc.php file -->