2012-04-07 101 views
0

我曾经为我的网站下载过这个购物车脚本。 但现在我想将值添加到购物车,但无法弄清楚如何... :(

我有下面的代码:

product.php

<form method="post" action="cart.php?action=update"> 
    <div class="quantity"> 
    <input type="text" name="qty<?php echo(''.$pinfo->id.''); ?>" value="1" /><span>&nbsp;&nbsp;&chi;</span> 
    </div> 
    <div class="add-quantity"> 
    <input class="nice-s" type="submit" name="product-quantity-submit" value="ORDER" /> 
    </div> 
</form> 

cart.php

$cart = $_SESSION['cust_cart']; 

if(isset($_GET['action'])) { 


$action = sanitize($_GET['action']); 
switch ($action) { 
    case 'add': 
     if ($cart) { 
      $cart .= ','.$_GET['id']; 
     } else { 
      $cart = $_GET['id']; 
     } 
     break; 
    case 'delete': 
     if ($cart) { 
      $items = explode(',',$cart); 
      $newcart = ''; 
      foreach ($items as $item) { 
       if ($_GET['id'] != $item) { 
        if ($newcart != '') { 
         $newcart .= ','.$item; 
        } else { 
         $newcart = $item; 
        } 
       } 
      } 
      $cart = $newcart; 
     } 
     break; 
    case 'update': 
/* if ($cart) { */ 
     $newcart = ''; 
     foreach ($_POST as $key=>$value) { 
      if (stristr($key,'qty')) { 
       $id = str_replace('qty','',$key); 
       $items = ($newcart != '') ? explode(',',$newcart) : explode(',',$cart); 
       $newcart = ''; 
       foreach ($items as $item) { 
        if ($id != $item) { 
         if ($newcart != '') { 
          $newcart .= ','.$item; 
         } else { 
          $newcart = $item; 
         } 
        } 
       } 
       for ($i=1;$i<=$value;$i++) { 
        if ($newcart != '') { 
         $newcart .= ','.$id; 
        } else { 
         $newcart = $id; 
        } 
       } 
      } 
     } 
/* } */ 
    $cart = $newcart; 
    break; 
} 

} 
$_SESSION['cust_cart'] = $cart; 

我想知道的是,我怎样才能通过product.php页面另一个值添加到购物车与以下字段:

<div class="size"> 
    <select name="size"> 
     <option value="16 INCH">16 INCH</option> 
     <option value="19 INCH">19 INCH</option> 
     <option value="22 INCH">22 INCH</option> 
    </div> 

Thanx提前! B)

回答

0

放置<form>标签内的<select>块(,一定要关闭<select>呢!您的例子没有显示正确的语法。),你应该能够通过访问变量$_POST["size"]来获取值。

我不知道这些数据正在做什么,但我建议将每个选项的值更改为没有空白的值。

+0

Thnx,只是作为一个例子,所以忘了关闭选择标签(一直发生在我身上;))我想实现的是将此值添加到购物车。因此,在购物车现在所持有的产品编号为2,数量为$ pinfo-> id的情况下,我希望将其扩展为尺寸。 – Baron85 2012-04-07 16:19:36

+0

@JoeyvanBilsen它的确取决于我们在这里谈论哪个脚本,它们都是以不同的方式编码的,并且在黑暗中说出你应该添加什么来实现这一点。有些脚本允许您在GUI中动态配置类似的选项,因此我建议您阅读脚本的文档并找到一种方法。 – esqew 2012-04-08 07:44:36

相关问题