-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_to_cart.php
executable file
·51 lines (43 loc) · 1.5 KB
/
add_to_cart.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
<?php
session_start();
require 'db.php';
$pid = $_SESSION['id'];
$imgurl = "img/";
$sql =" SELECT * FROM product WHERE id='$pid' ";
$result = $conn->query($sql);
?>
<table>
<tr>
<?php
if ($result->num_rows > 0) {
while ($row = $result->fetch_assoc() ) {
?>
<script type="text/javascript">
function getqty() {
var q = document.getElementById("qty").value;
var a = "<?= $row['price']?>";
var amnt = q * a;
document.getElementById("amount").value = amnt;
}
</script>
<form action="cart.php" method="get">
<td>
ID : <?= $row['id'] ?> <br>
Name : <?= $row['name'] ?> <br>
Price : <?= $row['price'] ?> <br>
Qty : <input id="qty" type="number" name="qty" min="1" max="10" value="<?= $_GET['qty']?>" onchange="getqty()"> <br><br>
Amount :<input type="text" name="amount" id="amount" value="<?=$row['price'] * $_GET['qty'] ?>">
</td>
<td>
<img src=" <?= $imgurl.$row['image'] ?> " width="150" height="200">
</td>
<?php
}
} $conn->close();
?>
</tr>
<tr>
<td> <input type="submit" name="crtsbmt" value="Add To Cart"> </td>
</tr>
</form>
</table>