Code 1 sur la mise en œuvre du panier en php
Cet article présente un code de panier implémenté en PHP. L'implémentation de la fonction est relativement complète. Il implémente le panier, les informations sur le client, le prix de l'adhésion et d'autres fonctions. C'est toujours bien. Les amis dans le besoin peuvent s'y référer.
1. Page d'affichage du produit<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>
<?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"); ?>
<?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>
<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>"; } ?>
<?php $conn=mysql_connect("localhost","root","") or die("数据库服务器连接错误".mysql_error()); mysql_select_db("shop",$conn) or die("数据库访问错误".mysql_error()); mysql_query("set character set gb2312"); mysql_query("set names gb2312"); ?>
Utilisez PHP pour implémenter la fonction de paiement d'Alipay sur l'application mobile
Comment utiliser PHP pour mettre en œuvre des fonctions de paiement rapide
Ce qui précède est le contenu détaillé de. pour plus d'informations, suivez d'autres articles connexes sur le site Web de PHP en chinois!

Outils d'IA chauds

Undresser.AI Undress
Application basée sur l'IA pour créer des photos de nu réalistes

AI Clothes Remover
Outil d'IA en ligne pour supprimer les vêtements des photos.

Undress AI Tool
Images de déshabillage gratuites

Clothoff.io
Dissolvant de vêtements AI

AI Hentai Generator
Générez AI Hentai gratuitement.

Article chaud

Outils chauds

Bloc-notes++7.3.1
Éditeur de code facile à utiliser et gratuit

SublimeText3 version chinoise
Version chinoise, très simple à utiliser

Envoyer Studio 13.0.1
Puissant environnement de développement intégré PHP

Dreamweaver CS6
Outils de développement Web visuel

SublimeText3 version Mac
Logiciel d'édition de code au niveau de Dieu (SublimeText3)

PHP 8.4 apporte plusieurs nouvelles fonctionnalités, améliorations de sécurité et de performances avec une bonne quantité de dépréciations et de suppressions de fonctionnalités. Ce guide explique comment installer PHP 8.4 ou mettre à niveau vers PHP 8.4 sur Ubuntu, Debian ou leurs dérivés. Bien qu'il soit possible de compiler PHP à partir des sources, son installation à partir d'un référentiel APT comme expliqué ci-dessous est souvent plus rapide et plus sécurisée car ces référentiels fourniront les dernières corrections de bogues et mises à jour de sécurité à l'avenir.

Visual Studio Code, également connu sous le nom de VS Code, est un éditeur de code source gratuit – ou environnement de développement intégré (IDE) – disponible pour tous les principaux systèmes d'exploitation. Avec une large collection d'extensions pour de nombreux langages de programmation, VS Code peut être c

Si vous êtes un développeur PHP expérimenté, vous aurez peut-être le sentiment d'y être déjà allé et de l'avoir déjà fait. Vous avez développé un nombre important d'applications, débogué des millions de lignes de code et peaufiné de nombreux scripts pour réaliser des opérations.

Ce tutoriel montre comment traiter efficacement les documents XML à l'aide de PHP. XML (Language de balisage extensible) est un langage de balisage basé sur le texte polyvalent conçu à la fois pour la lisibilité humaine et l'analyse de la machine. Il est couramment utilisé pour le stockage de données et

JWT est une norme ouverte basée sur JSON, utilisée pour transmettre en toute sécurité des informations entre les parties, principalement pour l'authentification de l'identité et l'échange d'informations. 1. JWT se compose de trois parties: en-tête, charge utile et signature. 2. Le principe de travail de JWT comprend trois étapes: la génération de JWT, la vérification de la charge utile JWT et l'analyse. 3. Lorsque vous utilisez JWT pour l'authentification en PHP, JWT peut être généré et vérifié, et les informations sur le rôle et l'autorisation des utilisateurs peuvent être incluses dans l'utilisation avancée. 4. Les erreurs courantes incluent une défaillance de vérification de signature, l'expiration des jetons et la charge utile surdimensionnée. Les compétences de débogage incluent l'utilisation des outils de débogage et de l'exploitation forestière. 5. L'optimisation des performances et les meilleures pratiques incluent l'utilisation des algorithmes de signature appropriés, la définition des périodes de validité raisonnablement,

Une chaîne est une séquence de caractères, y compris des lettres, des nombres et des symboles. Ce tutoriel apprendra à calculer le nombre de voyelles dans une chaîne donnée en PHP en utilisant différentes méthodes. Les voyelles en anglais sont a, e, i, o, u, et elles peuvent être en majuscules ou en minuscules. Qu'est-ce qu'une voyelle? Les voyelles sont des caractères alphabétiques qui représentent une prononciation spécifique. Il y a cinq voyelles en anglais, y compris les majuscules et les minuscules: a, e, i, o, u Exemple 1 Entrée: String = "TutorialSpoint" Sortie: 6 expliquer Les voyelles dans la chaîne "TutorialSpoint" sont u, o, i, a, o, i. Il y a 6 yuans au total

Liaison statique (statique: :) implémente la liaison statique tardive (LSB) dans PHP, permettant à des classes d'appel d'être référencées dans des contextes statiques plutôt que de définir des classes. 1) Le processus d'analyse est effectué au moment de l'exécution, 2) Recherchez la classe d'appel dans la relation de succession, 3) il peut apporter des frais généraux de performance.

Quelles sont les méthodes magiques de PHP? Les méthodes magiques de PHP incluent: 1. \ _ \ _ Construct, utilisé pour initialiser les objets; 2. \ _ \ _ Destruct, utilisé pour nettoyer les ressources; 3. \ _ \ _ Appel, gérer les appels de méthode inexistants; 4. \ _ \ _ GET, Implémentez l'accès à l'attribut dynamique; 5. \ _ \ _ SET, Implémentez les paramètres d'attribut dynamique. Ces méthodes sont automatiquement appelées dans certaines situations, améliorant la flexibilité et l'efficacité du code.
