Complete php shopping cart implementation code. 1. the Copy code on the product display page is as follows: tablecellspacing0cellpadding0trtdrowspan6divaligncenter? Phpif (trim ($ info [tu 1. product display page
The code is as follows:
If (trim ($ info [tupian] = "")) { Echo "no image "; } Else { ?> "Width =" 130 "height =" 100 "border =" 0 "> } ?>
|
|
【 ] |
|
[Market price: ] |
|
[Member price: ] |
|
["> View information] |
|
["> Add to shopping cart] |
|
[Remaining quantity: If ($ info [shuliang]-$ info [cishu])> 0) { Echo ($ info [shuliang]-$ info [cishu]); } Else { Echo "sold out "; } ?>] |
}
?>
2. file addgouwuche. php
The code is as follows:
Session_start ();
Include ("conn. php ");
If ($ _ SESSION [username] = "")
{
Echo "script" alert ('Please log on first and then shop! '); 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 ('This item has been sold out! '); History. back (); script ";
Exit;
}
$ Array = explode ("@", $ _ SESSION [producelist]);
For ($ I = 0; $ I {
If ($ array [$ I] ==$ id)
{
Echo "script" alert ('This item is already in your shopping cart! '); History. back (); script ";
Exit;
}
}
$ _ SESSION [producelist] =_ _ SESSION [producelist]. $ id ."@";
$ _ SESSION [quatity] =_ _ SESSION [quatity]. "1 @";
Header ("location: gouwu1.php ");
?>
3. file gouwu1.php
The code is as follows:
Session_start ();
If ($ _ SESSION [username] = "")
{
Echo "script" alert ('Please log on first and then shop! '); History. back (); script ";
Exit;
}
?>
Include ("top. php ");
?>
3. file gouwu2.php
The code is as follows: