Php shopping cart complete implementation code _ PHP Tutorial

Source: Internet
Author: User
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:


















Receiver information


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.