PHP로 장바구니를 구현하는 방법에 대한 코드 1
이 기사에서는 PHP로 구현된 장바구니 코드를 소개합니다. 장바구니, 주문자 정보, 멤버십 가격 및 기타 기능이 구현되어 있습니다.
1. 표시 페이지
<table width="255" border="0" cellspacing="0" cellpadding="0"> <tr> <td width="130" rowspan="6"><p align="center"> <?php if(trim($info[tupian]=="")) { echo "暂无图片"; } else { ?> <img src="<?php echo $info[tupian];?>" width="130" height="100" border="0"> <?php } ?> </p></td> <td width="20" height="16"> </td> <td width="113"><font color="EF9C3E">【<?php echo $info[mingcheng];?>】</font></td> </tr> <tr> <td height="16"> </td> <td><font color="910800">【市场价:<?php echo $info[shichangjia];?>】</font></td> </tr> <tr> <td height="16"> </td> <td><font color="DD4679">【会员价:<?php echo $info[huiyuanjia];?>】</font></td> </tr> <tr> <td height="16"> </td> <td>【<a href="lookinfo.php?id=<?php echo $info[id];?>">查看信息</a>】</td> </tr> <tr> <td height="16"> </td> <td>【<a href="addgouwuche.php?id=<?php echo $info[id];?>">放入购物车</a>】</td> </tr> <tr> <td height="16"> </td> <td><font color="13589B">【剩余数量: <?php if(($info[shuliang]-$info[cishu])>0) { echo ($info[shuliang]-$info[cishu]); } else { echo "已售完"; } ?>】</font></td> </tr> </table> <?php } ?> </table>
2. 파일 addgouwuche.php
<?php session_start(); include("conn.php"); if($_SESSION[username]=="") { echo "<script>alert('请先登录后购物!');history.back();</script>"; exit; } $id=strval($_GET[id]); $sql=mysql_query("select * from shangpin where id='".$id."'",$conn); $info=mysql_fetch_array($sql); if($info[shuliang]<=0) { echo "<script>alert('该商品已经售完!');history.back();</script>"; exit; } $array=explode("@",$_SESSION[producelist]); for($i=0;$i<count($array)-1;$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"); ?>
3. 파일 gouwu1.php
<?php session_start(); if($_SESSION[username]=="") { echo "<script>alert('请先登录,后购物!');history.back();</script>"; exit; } ?> <?php include("top.php"); ?> <table width="800" height="438" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="200" height="438" valign="top" bgcolor="#E8E8E8"><p align="center"> <?php include("left.php");?> </p></td> <td width="10" background="images/line2.gif"> </td> <td width="590" valign="top"><table width="550" height="10" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td> </td> </tr> </table> <table width="500" border="0" align="center" cellpadding="0" cellspacing="0"> <form name="form1" method="post" action="gouwu1.php"> <tr> <td height="25" bgcolor="#555555"><p align="center" style="color: #FFFFFF"><?php echo $_SESSION[username];?>的购物车</p></td> </tr> <tr> <td bgcolor="#555555"><table width="500" border="0" align="center" cellpadding="0" cellspacing="1"> <?php session_start(); session_register("total"); if($_GET[qk]=="yes") { $_SESSION[producelist]=""; $_SESSION[quatity]=""; } $arraygwc=explode("@",$_SESSION[producelist]); $s=0; for($i=0;$i<count($arraygwc);$i++) { $s+=intval($arraygwc[$i]); } if($s==0 ) { echo "<tr>"; echo" <td height='25' colspan='6' bgcolor='#FFFFFF' align='center'>您的购物车为空!</td>"; echo"</tr>"; } else { ?> <tr> <td width="125" height="25" bgcolor="#FFFFFF"><p align="center">商品名称</p></td> <td width="52" bgcolor="#FFFFFF"><p align="center">数量</p></td> <td width="64" bgcolor="#FFFFFF"><p align="center">市场价</p></td> <td width="64" bgcolor="#FFFFFF"><p align="center">会员价</p></td> <td width="51" bgcolor="#FFFFFF"><p align="center">折扣</p></td> <td width="66" bgcolor="#FFFFFF"><p align="center">小计</p></td> <td width="71" bgcolor="#FFFFFF"><p align="center">操作</p></td> </tr> <?php /** * 购物车 商品数量管理 * Edit www.jb51.net */ $total=0; $array=explode("@",$_SESSION[producelist]); $arrayquatity=explode("@",$_SESSION[quatity]); while(list($name,$value)=each($_POST)) { for($i=0;$i<count($array)-1;$i++) { if(($array[$i])==$name) { $arrayquatity[$i]=$value; } } } $_SESSION[quatity]=implode("@",$arrayquatity); for($i=0;$i<count($array)-1;$i++) { $id=$array[$i]; $num=$arrayquatity[$i]; if($id!="") { $sql=mysql_query("select * from shangpin where id='".$id."'",$conn); $info=mysql_fetch_array($sql); $total1=$num*$info[huiyuanjia]; $total+=$total1; $_SESSION["total"]=$total; ?> <tr> <td height="25" bgcolor="#FFFFFF"><p align="center"><?php echo $info[mingcheng];?></p></td> <td height="25" bgcolor="#FFFFFF"><p align="center"> <input type="text" name="<?php echo $info[id];?>" size="2" class="inputcss" value=<?php echo $num;?>> </p></td> <td height="25" bgcolor="#FFFFFF"><p align="center"><?php echo $info[shichangjia];?>元</p></td> <td height="25" bgcolor="#FFFFFF"><p align="center"><?php echo $info[huiyuanjia];?>元</p></td> <td height="25" bgcolor="#FFFFFF"><p align="center"><?php echo @(ceil(($info[huiyuanjia]/$info[shichangjia])*100))."%";?></p></td> <td height="25" bgcolor="#FFFFFF"><p align="center"><?php echo $info[huiyuanjia]*$num."元";?></p></td> <td height="25" bgcolor="#FFFFFF"><p align="center"><a href="removegwc.php?id=<?php echo $info[id]?>">移除</a></p></td> </tr> <?php } } ?> <tr> <td height="25" colspan="8" bgcolor="#FFFFFF"><p align="right"> <table width="500" height="25" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="125"><p align="center"> <input type="submit" value="更改商品数量" class="buttoncss"> </p></td> <td width="125"><p align="center"><a href="gouwu2.php">去收银台</a></p></td> <td width="125"><p align="center"><a href="gouwu1.php?qk=yes">清空购物车</a></p></td> <td width="125"><p align="left">总计:<?php echo $total;?></p></td> </tr> </table> </p></td> </tr> <?php } ?> </table></td> </tr> </form> </table></td> </tr> </table>
3. 파일 gouwu2.php
<table width="800" height="438" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td width="200" height="438" valign="top" bgcolor="#E8E8E8"><p align="center"> <?php include("left.php");?> </p></td> <td width="10" background="images/line2.gif"> </td> <td width="590" valign="top"><table width="550" height="15" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td> </td> </tr> </table> <table width="550" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td height="25" bgcolor="#555555"><p align="center" style="color: #FFFFFF">收货人信息</p></td> </tr> <tr> <td height="300" bgcolor="#555555"><table width="550" height="300" border="0" align="center" cellpadding="0" cellspacing="1"> <script language="javascript"> /** * 购物车 收货人信息 * Edit www.jb51.net */ function chkinput(form) { if(form.name.value=="") { alert("请输入收货人姓名!"); form.name.select(); return(false); } if(form.dz.value=="") { alert("请输入收货人地址!"); form.dz.select(); return(false); } if(form.yb.value=="") { alert("请输入收货人邮编!"); form.yb.select(); return(false); } if(form.tel.value=="") { alert("请输入收货人联系电话!"); form.tel.select(); return(false); } if(form.email.value=="") { alert("请输入收货人E-mail地址!"); form.email.select(); return(false); } if(form.email.value.indexOf("@")<0) { alert("收货人E-mail地址格式输入错误!"); form.email.select(); return(false); } return(true); } </script> <form name="form1" method="post" action="savedd.php" onSubmit="return chkinput(this)"> <tr> <td width="100" height="25" bgcolor="#FFFFFF"><p align="center">收货人姓名:</p></td> <td width="183" bgcolor="#FFFFFF"><p align="left"><input type="text" name="name" size="25" class="inputcss" style="background-color:#e8f4ff " onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"></p></td> <td width="86" bgcolor="#FFFFFF"><p align="center">性别:</p></td> <td width="176" bgcolor="#FFFFFF"><p align="left"> <select name="***"> <option selected value="男">男</option> <option value="女">女</option> </select> </p></td> </tr> <tr> <td height="25" bgcolor="#FFFFFF"><p align="center">详细地址:</p></td> <td height="25" colspan="3" bgcolor="#FFFFFF"><p align="left"><input name="dz" type="text" class="inputcss" id="dz" style="background-color:#e8f4ff " onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'" size="25"> </p></td> </tr> <tr> <td height="25" bgcolor="#FFFFFF"><p align="center">邮政编码:</p></td> <td height="25" colspan="3" bgcolor="#FFFFFF"><p align="left"><input type="text" name="yb" size="25" class="inputcss" style="background-color:#e8f4ff " onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"></p></td> </tr> <tr> <td height="25" bgcolor="#FFFFFF"><p align="center">联系电话:</p></td> <td height="25" colspan="3" bgcolor="#FFFFFF"><p align="left"><input type="text" name="tel" size="25" class="inputcss" style="background-color:#e8f4ff " onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"></p></td> </tr> <tr> <td height="25" bgcolor="#FFFFFF"><p align="center">电子邮箱:</p></td> <td height="25" colspan="3" bgcolor="#FFFFFF"><p align="left"><input type="text" name="email" size="25" class="inputcss" style="background-color:#e8f4ff " onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"></p></td> </tr> <tr> <td height="25" bgcolor="#FFFFFF"><p align="center">送货方式:</p></td> <td height="25" colspan="3" bgcolor="#FFFFFF"><p align="left"> <select name="shff" id="shff"> <option selected value="普通平邮">普通平邮</option> <option value="特快专递">特快专递</option> <option value="送货上门">送货上门</option> <option value="个人送货">个人送货</option> <option value="E-mail">E-mail</option> </select> </p></td> </tr> <tr> <td height="25" bgcolor="#FFFFFF"><p align="center">支付方式:</p></td> <td height="25" colspan="3" bgcolor="#FFFFFF"><p align="left"> <select name="zfff" id="zfff"> <option selected value="建设银行汇款">建设银行汇款</option> <option value="交通银行汇款">交通银行汇款</option> <option value="邮局汇款">邮局汇款</option> <option value="网上支付">网上支付</option> </select> </p></td> </tr> <tr> <td height="100" bgcolor="#FFFFFF"><p align="center">简单留言:</p></td> <td height="100" colspan="3" bgcolor="#FFFFFF"><p align="left"> <textarea name="ly" cols="60" rows="8" class="inputcss" style="background-color:#e8f4ff " onMouseOver="this.style.backgroundColor='#ffffff'" onMouseOut="this.style.backgroundColor='#e8f4ff'"></textarea> </p></td> </tr> <tr> <td height="25" colspan="4" bgcolor="#FFFFFF"><p align="center"><input type="submit" value="提交订单" class="buttoncss"> </p></td> </tr> </form> </table></td> </tr> </table></td> </tr> </table> <?php if($_GET[dingdanhao]!="") { $dd=$_GET[dingdanhao]; session_start(); $array=explode("@",$_SESSION[producelist]); $sum=count($array)*20+260; echo" <script language='javascript'>"; echo" window.open('showdd.php?dd='+'".$dd."','newframe','top=150,left=200,width=600,height=".$sum.",menubar=no,toolbar=no,location=no,scrollbars=no,status=no ')"; echo "</script>"; } ?>
4 입니다. 이 글의 전체 내용이 모든 분들의 학습에 도움이 되기를 바랍니다. 더 많은 관련 내용을 보시려면 PHP 중국어 웹사이트를 주목해주세요!
관련 추천:
PHP를 사용하여 모바일 APP에서 Alipay 결제 기능 구현PHP를 사용하여 빠른 현금 결제 기능 구현하는 방법위 내용은 PHP로 장바구니를 구현하는 방법에 대한 코드 1의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!

핫 AI 도구

Undresser.AI Undress
사실적인 누드 사진을 만들기 위한 AI 기반 앱

AI Clothes Remover
사진에서 옷을 제거하는 온라인 AI 도구입니다.

Undress AI Tool
무료로 이미지를 벗다

Clothoff.io
AI 옷 제거제

Video Face Swap
완전히 무료인 AI 얼굴 교환 도구를 사용하여 모든 비디오의 얼굴을 쉽게 바꾸세요!

인기 기사

뜨거운 도구

메모장++7.3.1
사용하기 쉬운 무료 코드 편집기

SublimeText3 중국어 버전
중국어 버전, 사용하기 매우 쉽습니다.

스튜디오 13.0.1 보내기
강력한 PHP 통합 개발 환경

드림위버 CS6
시각적 웹 개발 도구

SublimeText3 Mac 버전
신 수준의 코드 편집 소프트웨어(SublimeText3)

뜨거운 주제











PHP 8.4는 상당한 양의 기능 중단 및 제거를 통해 몇 가지 새로운 기능, 보안 개선 및 성능 개선을 제공합니다. 이 가이드에서는 Ubuntu, Debian 또는 해당 파생 제품에서 PHP 8.4를 설치하거나 PHP 8.4로 업그레이드하는 방법을 설명합니다.

숙련된 PHP 개발자라면 이미 그런 일을 해왔다는 느낌을 받을 것입니다. 귀하는 상당한 수의 애플리케이션을 개발하고, 수백만 줄의 코드를 디버깅하고, 여러 스크립트를 수정하여 작업을 수행했습니다.

VS Code라고도 알려진 Visual Studio Code는 모든 주요 운영 체제에서 사용할 수 있는 무료 소스 코드 편집기 또는 통합 개발 환경(IDE)입니다. 다양한 프로그래밍 언어에 대한 대규모 확장 모음을 통해 VS Code는

JWT는 주로 신분증 인증 및 정보 교환을 위해 당사자간에 정보를 안전하게 전송하는 데 사용되는 JSON을 기반으로 한 개방형 표준입니다. 1. JWT는 헤더, 페이로드 및 서명의 세 부분으로 구성됩니다. 2. JWT의 작업 원칙에는 세 가지 단계가 포함됩니다. JWT 생성, JWT 확인 및 Parsing Payload. 3. PHP에서 인증에 JWT를 사용하면 JWT를 생성하고 확인할 수 있으며 사용자 역할 및 권한 정보가 고급 사용에 포함될 수 있습니다. 4. 일반적인 오류에는 서명 검증 실패, 토큰 만료 및 대형 페이로드가 포함됩니다. 디버깅 기술에는 디버깅 도구 및 로깅 사용이 포함됩니다. 5. 성능 최적화 및 모범 사례에는 적절한 시그니처 알고리즘 사용, 타당성 기간 설정 합리적,

문자열은 문자, 숫자 및 기호를 포함하여 일련의 문자입니다. 이 튜토리얼은 다른 방법을 사용하여 PHP의 주어진 문자열의 모음 수를 계산하는 방법을 배웁니다. 영어의 모음은 A, E, I, O, U이며 대문자 또는 소문자 일 수 있습니다. 모음이란 무엇입니까? 모음은 특정 발음을 나타내는 알파벳 문자입니다. 대문자와 소문자를 포함하여 영어에는 5 개의 모음이 있습니다. a, e, i, o, u 예 1 입력 : String = "Tutorialspoint" 출력 : 6 설명하다 문자열의 "Tutorialspoint"의 모음은 u, o, i, a, o, i입니다. 총 6 개의 위안이 있습니다

이 튜토리얼은 PHP를 사용하여 XML 문서를 효율적으로 처리하는 방법을 보여줍니다. XML (Extensible Markup Language)은 인간의 가독성과 기계 구문 분석을 위해 설계된 다목적 텍스트 기반 마크 업 언어입니다. 일반적으로 데이터 저장 AN에 사용됩니다

정적 바인딩 (정적 : :)는 PHP에서 늦은 정적 바인딩 (LSB)을 구현하여 클래스를 정의하는 대신 정적 컨텍스트에서 호출 클래스를 참조 할 수 있습니다. 1) 구문 분석 프로세스는 런타임에 수행됩니다. 2) 상속 관계에서 통화 클래스를 찾아보십시오. 3) 성능 오버 헤드를 가져올 수 있습니다.

PHP의 마법 방법은 무엇입니까? PHP의 마법 방법은 다음과 같습니다. 1. \ _ \ _ Construct, 객체를 초기화하는 데 사용됩니다. 2. \ _ \ _ 파괴, 자원을 정리하는 데 사용됩니다. 3. \ _ \ _ 호출, 존재하지 않는 메소드 호출을 처리하십시오. 4. \ _ \ _ get, 동적 속성 액세스를 구현하십시오. 5. \ _ \ _ Set, 동적 속성 설정을 구현하십시오. 이러한 방법은 특정 상황에서 자동으로 호출되어 코드 유연성과 효율성을 향상시킵니다.
