-
Notifications
You must be signed in to change notification settings - Fork 14
/
mycart.php
95 lines (91 loc) · 2.84 KB
/
mycart.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
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
<?php
/**********************************/
/* file name: mycart.php */
/* infor: cart detail */
/**********************************/
include "config.inc.php"; //congif file
include "header.inc.php"; //header file
$session_id = session_id(); //user id
?>
<form action="updatecart.php" method="post">
<h2>cart</h2>
<table width="100%" border="0" cellpadding="4" cellspacing="1" bgcolor="#0066CC">
<tr bgcolor="#e7f0ff">
<th>image</th>
<th>product_name</th>
<th>price</th>
<th>number</th>
<th>amount</th>
<th>action</th>
</tr>
<?php
//get detail record in cart
$sql = "SELECT s.*, s.number*p.price AS amount,
p.product_id, p.product_name, p.price, p.photo FROM products p
JOIN carts s ON s.product_id=p.product_id
WHERE session_id='$session_id'
ORDER BY p.product_name DESC";
$result = mysql_query($sql);
@$numrows = mysql_num_rows($result);
//any product in cart?
if($numrows>0)
{
$total_price = 0;
//output shopping list
while($data = mysql_fetch_array($result))
{
$id = $data['product_id']; //product ID
$name = $data['product_name']; //product name
$price = $data['price']; //price
$number = $data['number']; //number
$amount = $data['amount']; //amount
$photo = ($data['photo'])
? $data['photo'] : 'default.gif'; //image
$total_price +=$amount; //total_price
?>
<tr align="center">
<td bgcolor="#FFFFFF">
<img src="uploads/<?php echo $photo ?>" width=100 height=50 border="0">
</td>
<td bgcolor="#FFFFFF">
<a href="show.php?product_id=<?php echo $id ?>">
<b><?php echo htmlspecialchars($name) ?></b></a>
</td>
<td bgcolor="#FFFFFF"><?php echo MoneyFormat($price) ?> Ԫ</td>
<td bgcolor="#FFFFFF">
<input type="text" name="p_<?php echo $id ?>"
value="<?php echo $number ?>" size=4 maxlength=3>
</td>
<td bgcolor="#FFFFFF"><?php echo MoneyFormat($amount) ?> Ԫ</td>
<td bgcolor="#FFFFFF">
<input name="delete" type="button" value="cancel" onClick="if(confirm('sure to cancel this product?'))
location.href='docart.php?action=editcart&product_id=<?php echo $id ?>&number=0'">
</td>
</tr>
<?php
}
?>
<!-- show total price-->
<tr bgcolor="#e7f0ff">
<td colspan="4" align="right"><strong>total_price</strong></td>
<td colspan="2"><strong><?php echo MoneyFormat($total_price) ?> $</strong></td>
</tr>
<?php
}else{
?>
<tr>
<td align="center" colspan="6" bgcolor="#FFFFFF">no product in cart</td>
</tr>
<?
}
?>
</table>
<p align="center">
<input type="submit" name="update_cart" value="update cart">
<input type="button" name="check_out" value="go to check out" onClick="location.href='checkout.php'">
</p>
</form>
<?php
include "footer.inc.php"; //footer
?>