첫 번째 장바구니 프로젝트를 만드는 중입니다.하지만 제품 수량을 업데이트하는 동안 멈추었습니다.PHP 장바구니 : 세션 변수를 사용하여 장바구니에서 제품 수량을 업데이트하는 방법은 무엇입니까?
세션 변수를 사용하여 제품 수량을 업데이트하고 싶습니다. 누구든지 코드를 알려주고 그 코드에 대해 어떻게 설명 할 수 있습니까? 여기
가 my_cart.php 페이지 코드<tr>
<th class="tablerow">Product Code</th>
<th class="tablerow">Product Name</th>
<th class="tablerow">Image</th>
<th class="tablerow">Quantity</th>
<th class="tablerow">Price</th>
<th class="tablerow">Total Price</th>
<th class="tablerow">Action</th>
</tr>
<?php
$grand_total = 0; // For Calculating Grand Price
foreach($_SESSION['cart'] as $id=>$quantity)
{
$sql="SELECT * FROM products WHERE id='$id'";
$result=mysql_query($sql) or die("Error Message");
while($row=mysql_fetch_array($result))
{
$grand_total+= $row['product_price']*$quantity; // For Calculating Grand Price
?>
<tr>
<td class="tablerow"><?php echo $row['id']; ?></td>
<td class="tablerow"><?php echo $row['product_name']; ?></td>
<td class="tablerow"><?php echo "<img height='50' width='50' src='admin/".$row['product_image']."'/>" ?></td>
<form name="update_cart" action="update_cart.php" method="post">
<td class="tablerow"><input type="text" name="quantity" value="<?php echo $quantity; ?>" /><br /><input type="image" src="admin/images/updatecart.png" name="Update" value="Update" /></td>
</form>
<td class="tablerow"><?php echo $row['product_price']; ?></td>
<td class="tablerow"><?php echo $quantity*$row['product_price']; ?> </td>
<td class="tablerow"><?php print "<a href='delete_cart.php?pid=".$row['id']."'><img src='admin/images/delete.png'></a>"; ?></td></form>
</tr>
<?php
}
}
?>
<tr>
<td class="tablerow" colspan="7">Grand Total: Rs <?php echo $grand_total; ?></td>
</tr>
<tr>
<td class="tablerow" colspan="7"><?php print "<a href='clear_cart.php'><img src='admin/images/clearcart.png'></a><a href='http://localhost/Shopping-Cart/front-end/'><img src='admin/images/continueshopping.png'></a><a href='update_cart.php'><img src='admin/images/placeorder.png'></a>";?></td>
</tr>
</table>
세션 변수를 사용하는 클라이언트 측. 다음은 add_cart.php 페이지 코드입니다. session_start(); if (isset ($ _ POST [ 'Buy'])) { \t $ pid = $ _ POST [ 'id']; \t \t $ _SESSION [ 'cart'] [$ pid] + = 1; 헤더 ("location : my_cart.php? msg = 제품이 성공적으로 추가되었습니다"); } – user3252609