PHP E-Commerce Shopping Cart Application step by step
In this Post We Will Explain About is PHP E-Commerce Shopping Cart Application step by step With Example and Demo.Welcome on Pakainfo.com – Examples, The best For Learn web development Tutorials,Demo with Example! Hi Dear Friends here u can know to Create Simple Shopping Cart with PHP and MysqlExample
In this post we will show you Best way to implement PHP Shopping Cart Tutorials : simple shopping cart in php source code, hear for PHP E-Commerce Shopping Cart Scriptswith Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.
Simple Shopping Cart with PHP
There are the following step by step Simple shopping Cart Application using PHP
1. Import simple database “mysql_import.sql” in your MySql login to PhpMyAdmin to create “item” table.
2. Change simple settings in database connection “config.php” for your database.
3. Navigate to simple default index page of your simple shopping cart and Good Luck.
PHP Shopping Cart Sample files Structure
images style online_cart_update.php config.php index.php mysql_import.sql online_view_cart.php
mysql_import.sql
CREATE TABLE IF NOT EXISTS `items` ( `id` int(11) NOT NULL AUTO_INCREMENT, `Item_Code` varchar(60) NOT NULL, `item_name` varchar(60) NOT NULL, `item_desc` tinytext NOT NULL, `item_img_name` varchar(60) NOT NULL, `cart_price` decimal(10,2) NOT NULL, PRIMARY KEY (`id`), UNIQUE KEY `Item_Code` (`Item_Code`) ) AUTO_INCREMENT=1 ; -- -- Dumping data for table `items` -- INSERT INTO `items` (`id`, `Item_Code`, `item_name`, `item_desc`, `item_img_name`, `cart_price`) VALUES (1, 'PD1001', 'red-MI Phone FX1', 'Di sertakan Pakainfo.com rambang live24u lansung tidak munasabah. Jika dalana ingin Pakainfo.com fake website free Download, itfiddle perlu itfiddle bahwa tiada apa live24u', 'android-phone.jpg', 200.50), (2, 'PD1002', 'Pakainfo.com DXT', 'Ia Pakainfo.com kamus live24u mengandungi itfiddle 800 ayat Pakainfo.com, bersama model dan itfiddle ayat Latin, more Pakainfo.com fake website free Download live24u munasabah.', 'live24ucom-tv.jpg', 500.85), (3, 'PD1003', 'more Hard Disk', 'Ada Pakainfo.com simple dari mukasurat-mukasurat fake website free Download live24u sedia ada, tetapi ashnbgiakam telah diubahsuai, natak jenaka karma, atau ayat ayat live24u', 'more-hard-disk.jpg', 100.00), (4, 'PD1004', 'lovely ghadiyar GE2', 'jiten akan terselit didalam di tengah tengah nests text. gana injin fake website free Download didalam step by step hanya new cretae text, dodiya menjadikan injin demao sebagai live24u terunggul dan bhatyat sekali di step by step.', 'lovely-watch.jpg', 400.30);
config.php
12, 'Service Tax' => 5 ); //simple connect to MySql Pakainfo.com $mysqli = new mysqli($db_host, $db_username, $db_password,$db_name); if ($mysqli->connect_error) { die('Error : ('. $mysqli->connect_errno .') '. $mysqli->connect_error); } ?>
index.php
Shopping Cart Items
0) { echo ''; echo ''; } ?> query("SELECT Item_Code, item_name, item_desc, item_img_name, cart_price FROM items ORDER BY id ASC"); if($data_res){ $items_item = 'Your Shopping Cart
'; echo ''; echo '
- ';
//fetch data_res set as object and output HTML
while($obj = $data_res->fetch_object())
{
$items_item .= <<<EOT
- EOT; } $items_item .= '
online_view_cart.php
View shopping cart View Cart
online_cart_update.php
0) { foreach($_POST as $key => $value){ //add all post vars to cnew_prod array $cnew_prod[$key] = filter_var($value, FILTER_SANITIZE_STRING); } //remove unecessary vars unset($cnew_prod['type']); unset($cnew_prod['live_rurl']); //we need to get item name and cart_price from database. $myquery = $mysqli->prepare("SELECT item_name, cart_price FROM items WHERE Item_Code=? LIMIT 1"); $myquery->bind_param('s', $cnew_prod['Item_Code']); $myquery->execute(); $myquery->bind_result($item_name, $cart_price); while($myquery->fetch()){ //fetch item name, cart_price from db and add to cnew_prod array $cnew_prod["item_name"] = $item_name; $cnew_prod["item_cart_price"] = $cart_price; if(isset($_SESSION["cart_items"])){ //if session var already exist if(isset($_SESSION["cart_items"][$cnew_prod['Item_Code']])) //check item exist in items array { unset($_SESSION["cart_items"][$cnew_prod['Item_Code']]); //unset old array item } } $_SESSION["cart_items"][$cnew_prod['Item_Code']] = $cnew_prod; //update or create item session with new item } } //update or remove items if(isset($_POST["item_qty"]) || isset($_POST["delete_code"])) { //update item quantity in item session if(isset($_POST["item_qty"]) && is_array($_POST["item_qty"])){ foreach($_POST["item_qty"] as $key => $value){ if(is_numeric($value)){ $_SESSION["cart_items"][$key]["item_qty"] = $value; } } } //remove an item from item session if(isset($_POST["delete_code"]) && is_array($_POST["delete_code"])){ foreach($_POST["delete_code"] as $key){ unset($_SESSION["cart_items"][$key]); } } } $live_rurl = (isset($_POST["live_rurl"]))?urldecode($_POST["live_rurl"]):''; //return url header('Location:'.$live_rurl); ?>
I hope you have Got What is Create Simple Shopping Cart with PHP and Mysql And how it works.I would Like to have FeadBack From My Blog(Pakainfo.com) readers.Your Valuable FeadBack,Any Question,or any Comments abaout This Article(Pakainfo.com) Are Most Always Welcome.