Php shopping cart solution

Source: Internet
Author: User
Php shopping cart & lt ;! DOCTYPEhtmlPUBLIC & quot;-// W3C // DTDXHTML1.0Transitional // EN & quot; http://www.w3.org/TR/xhtml1/DTD/xhtml1-tra php shopping cart




Untitled Document



Homepage shopping basket history exit

$ Con = mysql_connect ("localhost", "root ","");
If (! $ Con)
{
Die ('could not connect: '. mysql_error ());
}

$ Db_selected = mysql_select_db ("user", $ con );
$ SQL = "select * from produce"; // query all products
$ Rs = mysql_query ($ SQL, $ con); // run the SQL statement to obtain a result set.
While ($ row = mysql_fetch_array ($ rs) // traverses the result set
{
?>


 












Src = "images/ "Width =" 123 "height =" 121 "border =" 0 "/> Goods name:
Goods price:
& Pname = Echo $ row ["pname"]?> "> Purchase

}
?>



------ Solution --------------------
What do you want to ask? There is an encoded text.

Isn't it easier for others to solve the problem for you to highlight the content with the corresponding source code?
------ Solution --------------------
$ Act = $ _ GET [act];
$ Product_id = $ _ GET [prcid];

If ($ act = "add ")
{
$ Cars_id = explode (",", $ _ COOKIE [buypro]);
// Echo"
";
//print_r($cars_id);
//echo"
";
// Exit;
Foreach ($ cars_id as $ pr_id)
{
If ($ pr_id = $ product_id)
{
Echo "script" alert ('you have purchased this item. Please check your shopping cart! '); Location. href = 'Car. php'; script ";
Exit;
}
}

If (empty ($ _ COOKIE [buypro])
{
Setcookie ("buypro", $ product_id, time () + 3600 );
Setcookie ("buycount", "1", time () + 3600 );
}
Else
{
$ Newpro = $ _ COOKIE [buypro]. ",". $ product_id;
$ Newcount = $ _ COOKIE [buycount]. ",". "1 ";
Setcookie ("buypro", $ newpro, time () + 3600 );
Setcookie ("buycount", $ newcount, time () + 3600 );
}
}
// Delete
If ($ act = "del ")
{
$ Buy = $ _ COOKIE [buypro];
$ Cars_id = explode (",", $ buy );
$ Buycountary = explode (",", $ _ COOKIE [buycount]);
$ Newid = array ();
$ Carcount = array ();
For ($ I = 0; $ I {
If ($ cars_id [$ I]! = $ Product_id)
{
$ Newid [] = $ cars_id [$ I];
$ Carcount [] = $ buycountary [$ I];
}
}

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.