>  기사  >  백엔드 개발  >  关于购物车实现的小问题 谢谢大家

关于购物车实现的小问题 谢谢大家

WBOY
WBOY원래의
2016-06-20 12:35:40893검색

session_start();
include("conn/conn.php");
if($_SESSION[username]==""){
  echo "<script>alert('请先登录后购物!');history.back();</script>"; 
  exit;
 }
$id=strval($_GET[id]);
$sql=mysql_query("select * from tb_shangpin where id='".$id."'",$conn); 
$info=mysql_fetch_array($sql);
if($info[shuliang]   echo "<script>alert('该商品已经售完!');history.back();</script>";
   exit;
 }
  $array=explode("@",$_SESSION[producelist]);
  for($i=0;$i  if($array[$i]==$id){
     echo "<script>alert('该商品已经在您的购物车中!');history.back();</script>";
 exit;
  }
}
  $_SESSION[producelist]=$_SESSION[producelist].$id."@";
  $_SESSION[quatity]=$_SESSION[quatity]."1@";
  header("location:gouwu1.php");
?> 
上面的count ($array)为什么还要减一啊谢谢大家


回复讨论(解决方案)

因为每次增加商品时:$_SESSION[producelist]=$_SESSION[producelist].$id."@";
$_SESSION[producelist] 的内容以 @ 结束
explode 后,$array 最后一个元素为空

因为每次增加商品时:$_SESSION[producelist]=$_SESSION[producelist].$id."@";
$_SESSION[producelist] 的内容以 @ 结束
explode 后,$array 最后一个元素为空

真心谢谢你
성명:
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.