从购物车中删除项目 - php

时间:2012-03-28 10:37:46

标签: php cart

我正在尝试使用“删除”链接从购物篮中删除商品。目前,当点击链接时,它没有做任何事情。如果可能的话,请有人引导我朝着正确的方向前进。我有一个循环的每个项目的顺序,其中$ item将是当前项目,$ key是数组的索引。

然后我使用html输出项目。在本节中,我有一个删除链接:

<td><a href="processorder.php?delete=<?=$key?>">Delete</a></td>

我也有这个过程:

if (isset($_GET['delete']) && $_GET['delete']) {
$key = $_GET['delete'];
unset($_SESSION['order'][$key]);
}

以下是所有参考代码:

<?php
// start the session handler
require_once('dbfunction.php');

//connect to database
$conn = DB();

require_once('header.php');

 if (isset($_GET['delete']) && $_GET['delete']) {
$key = $_GET['delete'];
unset($_SESSION['order'][$key]);
}

//first of all, get this items information
  $query = "SELECT * FROM ".$tablename." WHERE ".$key." = '".$item['prod_id']."'";
  $sql = mysql_query($query, $conn);

  $product = mysql_fetch_assoc($sql);

  //html for this product
  $grand_total = isset($grand_total) ? $grand_total : 0;
  $line_cost = $product['price'] * $item['quantity'];
  $grand_total += $line_cost;
  ?>

  <tr>
    <td><?=$product['common_name'];?></td>
    <td><?=$item['prod_type'];?></td>
    <td><?=$product['price'];?></td>
    <td><input type='text' name='quantity[]' value='<?=$item['quantity'];?>' size='2' /></td>
    <td>&pound;<?=number_format($line_cost, 2);?></td>
    <td><a href="processorder.php?delete=<?=$key?>">Delete</a></td>
  </tr>
  <?php
}
?>

0 个答案:

没有答案