Tagged: simple php shopping cart with paypal

Simple PHP Shopping Cart 0

Simple PHP Shopping Cart

Simple PHP Shopping Cart

In this Post We Will Explain About is Simple PHP Shopping Cart 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 Simple PHP Shopping Cart Example

In this post we will show you Best way to implement Simple PHP Shopping Cart, hear for Simple PHP Shopping Cart with Download .we will give you demo,Source Code and examples for implement Step By Step Good Luck!.

Database(Simple PHP Shopping Cart)

   --  
 -- Table structure for table `live_computer_products`  
 --  
 CREATE TABLE IF NOT EXISTS `tbl_product` (  
  `id` int(11) NOT NULL AUTO_INCREMENT,  
  `name` varchar(255) NOT NULL,  
  `image` varchar(255) NOT NULL,  
  `price` double(10,2) NOT NULL,  
  PRIMARY KEY (`id`)  
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;  
 --  
 -- Dumping data for table `live_computer_products`  
 --  
 INSERT INTO `live_computer_products` (`id`, `name`, `image`, `price`) VALUES  
 (1, 'Lenovo live', 'lenovo.jpg', 100.00),  
 (2, 'packagedownload', 'mntoag.jpg', 299.00),  
 (3, 'redmi4A', 'mobile.jpg', 125.00);

Include External Libs

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js"></script>  
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css" />  
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>

index.php

 <?php   
 session_start();  
 $connect = mysqli_connect("localhost", "USERNAME", "YOUR_PASSWORD", "YOUR_DATABASENAME");  
 if(isset($_POST["cart_add_examle"]))  
 {  
      if(isset($_SESSION["live_shopCart_simple"]))  
      {  
           $product_array_id = array_column($_SESSION["live_shopCart_simple"], "product_id");  
           if(!in_array($_GET["id"], $product_array_id))  
           {  
                $count = count($_SESSION["live_shopCart_simple"]);  
                $product_array = array(  
                     'product_id'               =>     $_GET["id"],  
                     'product_name'               =>     $_POST["hidden_name"],  
                     'product_price'          =>     $_POST["hidden_price"],  
                     'product_qty'          =>     $_POST["product_qty"]  
                );  
                $_SESSION["live_shopCart_simple"][$count] = $product_array;  
           }  
           else  
           {  
                echo '<script>alert("Product Already Added")</script>';  
                echo '<script>window.location="index.php"</script>';  
           }  
      }  
      else  
      {  
           $product_array = array(  
                'product_id'               =>     $_GET["id"],  
                'product_name'               =>     $_POST["hidden_name"],  
                'product_price'          =>     $_POST["hidden_price"],  
                'product_qty'          =>     $_POST["product_qty"]  
           );  
           $_SESSION["live_shopCart_simple"][0] = $product_array;  
      }  
 }  
 if(isset($_GET["action"]))  
 {  
      if($_GET["action"] == "delete")  
      {  
           foreach($_SESSION["live_shopCart_simple"] as $keys => $data_val)  
           {  
                if($data_val["product_id"] == $_GET["id"])  
                {  
                     unset($_SESSION["live_shopCart_simple"][$keys]);  
                     echo '<script>alert("Product Removed")</script>';  
                     echo '<script>window.location="index.php"</script>';  
                }  
           }  
      }  
 }  
 ?>  
<!DOCTYPE html>  
 <html>  
      <head>  
           <title>Pakainfo.com Tutorial | Simple PHP Mysql Shopping Cart using jquery</title>  
            
      </head>  
      <body>  
           <br />  
           <div class="container live" style="width:800px;">  
                <h3 align="center">Simple PHP Mysql Shopping Cart</h3><br />  
                <?php  
                $query = "SELECT * FROM live_computer_products ORDER BY id ASC";  
                $result = mysqli_query($connect, $query);  
                if(mysqli_num_rows($result) > 0)  
                {  
                     while($data_row = mysqli_fetch_array($result))  
                     {  
                ?>  
                <div class="col-md-4">  
                     <form method="post" action="index.php?action=add&id=<?php echo $data_row["id"]; ?>">  
                          <div style="border:2px solid #333; background-color:#3d3d3d; border-radius:5px; padding:16px;" align="center">  
                               <img src="<?php echo $data_row["image"]; ?>" class="img-responsive" /><br />  
                               <h4 class="text-info"><?php echo $data_row["name"]; ?></h4>  
                               <h4 class="text-danger">$ <?php echo $data_row["price"]; ?></h4>  
                               <input type="text" name="product_qty" class="live form-control" value="1" />  
                               <input type="hidden" name="hidden_name" value="<?php echo $data_row["name"]; ?>" />  
                               <input type="hidden" name="hidden_price" value="<?php echo $data_row["price"]; ?>" />  
                               <input type="submit" name="cart_add_examle" style="margin-top:4px;" class="btn btn-success" value="Add to Cart" />  
                          </div>  
                     </form>  
                </div>  
                <?php  
                     }  
                }  
                ?>  
                <div style="clear:both"></div>  
                <hr />  
                <h3>Order Details</h3>  
                <div class="table-responsive">  
                     <table class="table">  
                          <tr>  
                               <th>Product Name</th>  
                               <th>Product Qty</th>  
                               <th>Product Price</th>  
                               <th>Product Total</th>  
                               <th>Product Action</th>  
                          </tr>  
                          <?php   
                          if(!empty($_SESSION["live_shopCart_simple"]))  
                          {  
                               $total = 0;  
                               foreach($_SESSION["live_shopCart_simple"] as $keys => $data_val)  
                               {  
                          ?>  
                          <tr>  
                               <td><?php echo $data_val["product_name"]; ?></td>  
                               <td><?php echo $data_val["product_qty"]; ?></td>  
                               <td>$ <?php echo $data_val["product_price"]; ?></td>  
                               <td>$ <?php echo number_format($data_val["product_qty"] * $data_val["product_price"], 2); ?></td>  
                               <td><a href="index.php?action=delete&id=<?php echo $data_val["product_id"]; ?>"><span class="text-danger">Remove</span></a></td>  
                          </tr>  
                          <?php  
                                    $total = $total + ($data_val["product_qty"] * $data_val["product_price"]);  
                               }  
                          ?>  
                          <tr>  
                               <td colspan="3" align="right">Total</td>  
                               <td align="right">$ <?php echo number_format($total, 2); ?></td>  
                               <td></td>  
                          </tr>  
                          <?php  
                          }  
                          ?>  
                     </table>  
                </div>  
           </div>  
           <br />  
      </body>  
 </html>

You are Most welcome in my youtube Channel Please subscribe my channel. and give me FeedBack.
More Details……
Angularjs Example

Example

I hope you have Got What is Simple PHP Shopping Cart And how it works.I would Like to have FeedBack From My Blog(Pakainfo.com) readers.Your Valuable FeedBack,Any Question,or any Comments about This Article(Pakainfo.com) Are Most Always Welcome.