0

我有购物车页面,但问题是点击时我无法从购物车中删除商品remove button

1) 我想通过基于产品的方式从购物车中删除商品pid
2)当我回显$pid=intval($pid);它显示PID?在购物车页面?

产品页面

session_start();
$id=$_REQUEST['id'];
$_SESSION['pid1']= $_POST['ids']; //Product ID//

<form method="post">
 <input type="hidden" name="ids" value="<?php echo $id?>" />
</form>

<input type="submit" class="button1" name="addtocart" value="Add To Cart"
/>

</form>

购物车页面

session_start();
$pid=$_SESSION['pid1'];   

if($_REQUEST['command']=='delete' && $pid>0){
  $pid=intval($pid);
  $max=count($_SESSION['product1']);
  for($i=0;$i<$max;$i++){
    if($pid==$_SESSION['product1'][$i]['pid']){
      unset($_SESSION['product1'][$i]);
      break;
    }
  }
  $_SESSION['product1']=array_values($_SESSION['product1']);
}


<form  name="form1" method="post">  
<input type="hidden" name="pid" />
<input type="hidden" name="command" />  

<a href="javascript:del(<?php echo $pid?>)">
<input type="button" class="button2" value="Remove" />
</a>

购物车页面 Javascript

<script language="javascript">
function del(pid){
if(confirm('Do you really mean to delete this item')){
document.form1.pid.value=pid;
document.form1.command.value='delete';
document.form1.submit();
}
}

function clear_cart(){
if(confirm('This will empty your shopping cart, continue?')){
document.form1.command.value='clear';
document.form1.submit();
}
}

4

1 回答 1

0

请修改您的表格:-

  <form  name="form1" method="post">     
  <input type="hidden" name="pid" value="<?php echo $pid?>" />
  <input type="hidden" name="command" value="delete" /> 
  <input type="button" class="button2" value="Remove" onclick="javascript:del(<?php echo $pid?>)" />
  </form>
于 2013-04-22T13:41:03.840 回答