ICTtask works best with JavaScript enabled.

 

customer accout logout by using PHP OOP, PDO,COOKIE,AJAX(E-Commerce website-part 9)

Live Demo
post thumbnail
Source Code
Hi there, In previous part we have made customer accout login by using jquery, ajax with bootstrap modal. So now we make customer accout logout by using cookie. Now we write jquery code for logout option when click the logout option so we sent a request to customer action file by using ajax request then customer action into we will write code for unset cookie. Please Follow our video tutorial We have also provide source code and live online demo. In next video tutorial we will make discussing on Customer Order View & account Update by using PHP OOP PDO. So friend please share this post.Thanks Next Tutorilas Link these:
    Files structure Follow:
  • Application root folder
    • // classes/Cart.php
    • // Cart class
    • // classes/Tabs.php
    • // Tabs class
    • // classes/Customer.php
    • // Customer class
    • // config/config.php
    • // config file
    • // lib/DB.php
    • // database file
    • upload
    • // upload folder
    • action.php
    • // action file
    • index.php
    • // view page

Sourse Code:

  • Customer.php

  • <?php
    /**
    *  Customer Class
    */
      require_once "/../lib/DB.php";
      class Customer 
      {
        private $db;
        function __construct()
        {
          $this->db = new DB();
        }
    
        public function sameUserNameCheck($table,$c_user_name){
          $sql = "SELECT * FROM $table WHERE c_user_name =?";
          return $this->db->affectedUserName($sql,$c_user_name);
    
        }
        public function customerAccountCreate($table,$data){
          return $this->db->insert($table,$data);
        }
    
        public function authLoginCheck($table,$c_user_name_l,$c_pass_l){
          $sql = "SELECT * FROM $table WHERE c_user_name=? AND c_pass=?";
          return $this->db->affectedRow($sql,$c_user_name_l,$c_pass_l);
    
        }
    
        public function fetchCustomerInfo($table,$c_user_name_l,$c_pass_l){
          $sql = "SELECT * FROM $table WHERE    c_user_name ='$c_user_name_l' AND   c_pass='$c_pass_l' ";
          return $this->db->select($sql);
        }
    
      }
    
  • Cart.php

  • <?php
    /**
    *  Cart Class
    */
      require_once "/../lib/DB.php";
      class Cart 
      {
        private $db;
        function __construct()
        {
          $this->db = new DB();
        }
    
        public function addToCart($table,$data){
          return $this->db->insert($table,$data);
        }
         
        public function affectCart($table,$s_id,$pd_id){
          $sql = "SELECT * FROM $table WHERE    s_id=? AND pd_id=?";
          return $this->db->affectedRow($sql,$s_id,$pd_id);
        }
    
        public function getCartList($table){
          $S_ID = $_COOKIE['cart_item'];
          $sql = "SELECT * FROM $table WHERE s_id ='$S_ID' ORDER BY cart_id DESC";
          return $this->db->select($sql);
        }
    
        public function getCartListCount($table){
          $S_ID = $_COOKIE['cart_item'];
          $sql = "SELECT * FROM $table WHERE s_id ='$S_ID' ";
          return $this->db->cartListCount($sql);
        }
    
        public function pd_quantity_up($table,$data,$cond){
          return $this->db->update($table,$data,$cond);
    
        } 
        
    
    
    
      }
    
  • Tabs.php

  • <?php
    /**
    *  Tabs class
    */
      require_once "/../lib/DB.php";
      
      class Tabs 
      {
        private $db;
        
        function __construct()
        {
          $this->db = new DB();
        }
        public function fetchDynamicCat(){
          $sql = "SELECT * FROM tbl_product_cat";
          return $this->db->select($sql);
        }
    
        public function fetchProductByCat($getCatID){
          $sql = "SELECT * FROM tbl_product WHERE pd_cat_id = $getCatID ORDER BY    pd_id DESC";
          return $this->db->select($sql);
        }
    
    
      }
    
  • config.php

  • <?php
    define("HOSTName", "localhost");
    define("USERName", "root");
    define("USERpass", "");
    define("DBname", "ecommerce");
    
    
  • DB.php

  • <?php
    /**
    *  DB Class
    */      
          require_once "/../config/config.php";
    
        class DB 
        {
          public $DBConnect;
          private $HOSTName = HOSTName;
          private $USERName = USERName;
          private $USERpass = USERpass;
          private $DBname = DBname;
          function __construct()
          {
            $this->DBConnect();
          }
    
          public function DBConnect(){
            try{
            $this->DBConnect = new PDO('mysql:host='.$this->HOSTName.';dbname='.$this->DBname,$this->USERName,$this->USERpass);
    
            }catch(PDOException $e){
              echo "Connection Fail..".$e->getMessage();
            }
          }
    
          public function select($sql){
            $stmt = $this->DBConnect->prepare($sql);
            $stmt->execute();
            return $stmt->fetchAll(PDO::FETCH_ASSOC);
          }
    
          public function insert($table,$data){
            $keys = implode(',', array_keys($data));
            $values = ":".implode(',:', array_keys($data));
            
            $sql = "INSERT INTO $table($keys) VALUES($values)";
            $stmt = $this->DBConnect->prepare($sql);
            foreach ($data as $key => $value) {
              $stmt->bindValue(":$key",$value);
            }
            return $stmt->execute();
    
            }
    
            public function affectedRow($sql,$s_id,$pd_id){
              $stmt = $this->DBConnect->prepare($sql);
              $stmt->execute(array($s_id,$pd_id));
              return $stmt->rowCount();
            }
    
            public function cartListCount($sql){
            $stmt = $this->DBConnect->prepare($sql);
            $stmt->execute();
            return $stmt->rowCount();
            }
    
            public function update($table,$data,$cond){
              
              $getKeys ='';
              foreach ($data as $keys => $values) {
                $getKeys .="$keys=:pd_quantity,";
              }
              $getKeys = rtrim($getKeys,",");
    
            $sql = "UPDATE $table SET   $getKeys  WHERE  $cond";
              $stmt = $this->DBConnect->prepare($sql);
              foreach ($data as $key => $value) {
                $stmt->bindValue(":$key",$value);
              }
              $stmt->execute();
              return $stmt->rowCount();
    
            } 
    
            
    
          
    
        }
    
  • action.php

  • customer_action.php

  • index.php

  • 
    
    
    --
    -- Database: `ecommerce`
    --
    
    -- --------------------------------------------------------
    
    --
    -- Table structure for table `tbl_cart`
    --
    
    CREATE TABLE `tbl_cart` (
      `cart_id` int(11) NOT NULL,
      `s_id` varchar(255) NOT NULL,
      `pd_id` int(11) NOT NULL,
      `pd_name` varchar(255) NOT NULL,
      `pd_image` varchar(255) NOT NULL,
      `pd_price` varchar(11) NOT NULL,
      `pd_quantity` int(11) NOT NULL,
      `pd_added_time` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    --
    -- Dumping data for table `tbl_cart`
    --
    
    INSERT INTO `tbl_cart` (`cart_id`, `s_id`, `pd_id`, `pd_name`, `pd_image`, `pd_price`, `pd_quantity`, `pd_added_time`) VALUES
    (63, 'pnqfrnt88m4vjmjqqntpi5u606', 12, 'Turkish Towel Monogrammed', '51nNshZc2iL._AC_US160_.jpg', '15', 2, '2018-05-03 16:52:43'),
    (64, 'pnqfrnt88m4vjmjqqntpi5u606', 11, 'Party Glitter Paper Cake Topper', '51c-eFDruIL._AC_US160_.jpg', '13', 2, '2018-05-03 16:52:59'),
    (65, 'pnqfrnt88m4vjmjqqntpi5u606', 10, 'home stemless wine glass', '416MiOq22OL._AC_US160_.jpg', '12', 3, '2018-05-03 16:53:05'),
    (66, 'pnqfrnt88m4vjmjqqntpi5u606', 7, 'Bullet Rocks Glass', '41CYU7b7yrL._AC_US160_.jpg', '19', 2, '2018-05-03 16:53:14'),
    (67, 'pnqfrnt88m4vjmjqqntpi5u606', 8, 'Metal Wallet Card', '51gW-OKmBcL._AC_US160_.jpg', '16', 2, '2018-05-03 16:53:19'),
    (68, 'pnqfrnt88m4vjmjqqntpi5u606', 23, 'Children 1st Birthday Great ', '41q-Q4Zz+4L._AC_US160_.jpg', '19', 1, '2018-05-03 18:50:27'),
    (69, 'pnqfrnt88m4vjmjqqntpi5u606', 24, 'APPLE MAGIC KEYBOARD', 'mla22za-2.jpg', '10,000 ', 2, '2018-05-03 20:56:24'),
    (70, 'uq54c3jit42pm1qmgjnn3mu7s0', 11, 'Party Glitter Paper Cake Topper', '51c-eFDruIL._AC_US160_.jpg', '13', 2, '2018-05-03 21:04:06'),
    (71, 'uq54c3jit42pm1qmgjnn3mu7s0', 10, 'home stemless wine glass', '416MiOq22OL._AC_US160_.jpg', '12', 3, '2018-05-03 21:04:10'),
    (82, 'kdvjab8rqd4vph2obktmatqh64', 12, 'Turkish Towel Monogrammed', '51nNshZc2iL._AC_US160_.jpg', '15', 24, '2018-05-04 14:05:33'),
    (87, 'cca19tmged9bpjsn7vdaqooqq0', 26, 'Apple Macbook Pro', 'apple-macbook-pro-mid-2017-s-3_1.jpg', '2134', 1, '2018-05-06 09:45:28'),
    (88, 'cca19tmged9bpjsn7vdaqooqq0', 27, 'HP ENVY 13-AD104TU', '13-ad042tx-silk-gold-3_1.jpg', '9105', 2, '2018-05-06 09:45:33'),
    (89, 'cca19tmged9bpjsn7vdaqooqq0', 25, 'Apple Macbook Pro', 'mptt2ll-3.jpg', '2445 ', 2, '2018-05-06 09:45:38'),
    (90, 'cca19tmged9bpjsn7vdaqooqq0', 24, 'APPLE MAGIC KEYBOARD', 'mla22za-2.jpg', '10,000 ', 1, '2018-05-06 09:45:42'),
    (91, 'cca19tmged9bpjsn7vdaqooqq0', 19, 'Groomsmen Flasks Gift', '91JkAGk-32L._AC_SX220_SY220_.jpg', '27', 8, '2018-05-07 19:38:14'),
    (92, 'cca19tmged9bpjsn7vdaqooqq0', 12, 'Turkish Towel Monogrammed', '51nNshZc2iL._AC_US160_.jpg', '15', 3, '2018-05-06 23:31:47');
    
    -- --------------------------------------------------------
    
    --
    -- Table structure for table `tbl_customer`
    --
    
    CREATE TABLE `tbl_customer` (
      `c_id` int(11) NOT NULL,
      `c_user_name` varchar(255) NOT NULL,
      `c_pass` varchar(50) NOT NULL,
      `c_invoice` varchar(50) NOT NULL,
      `c_name` varchar(255) NOT NULL,
      `c_address` varchar(255) NOT NULL,
      `c_phone` varchar(255) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    --
    -- Dumping data for table `tbl_customer`
    --
    
    INSERT INTO `tbl_customer` (`c_id`, `c_user_name`, `c_pass`, `c_invoice`, `c_name`, `c_address`, `c_phone`) VALUES
    (26, 'programmer', '81dc9bdb52d04dc20036dbd8313ed055', '455697', 'Programmer', 'Dinajpur', '+880 177 000000'),
    (27, 'mondol', '81dc9bdb52d04dc20036dbd8313ed055', '525895', 'Rayhan Mondol', 'Dinajpur', '+880 177 000000'),
    (28, 'rr', 'c4ca4238a0b923820dcc509a6f75849b', '292577', 'e', 'e', '43');
    
    -- --------------------------------------------------------
    
    --
    -- Table structure for table `tbl_product`
    --
    
    CREATE TABLE `tbl_product` (
      `pd_id` int(11) NOT NULL,
      `pd_cat_id` int(11) NOT NULL,
      `pd_name` varchar(255) NOT NULL,
      `pd_image` varchar(255) NOT NULL,
      `pd_des` text NOT NULL,
      `pd_price` varchar(255) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    --
    -- Dumping data for table `tbl_product`
    --
    
    INSERT INTO `tbl_product` (`pd_id`, `pd_cat_id`, `pd_name`, `pd_image`, `pd_des`, `pd_price`) VALUES
    (6, 3, 'Custom Cosmetic Bag', '519XCb99oZL._AC_US160_.jpg', 'Pink and White Seersucker Make Up Bag, Custom Cosmetic Bag, Personalized Cosmetic Bag', '12'),
    (7, 3, 'Bullet Rocks Glass', '41CYU7b7yrL._AC_US160_.jpg', 'The Original BenShot Bullet Rocks Glass with Real Bullet 0.308 Made in the USA', '19'),
    (8, 3, 'Metal Wallet Card', '51gW-OKmBcL._AC_US160_.jpg', 'Engraved Aluminum Wallet Love Note Insert, Metal Wallet Card Insert, Mini Love Note - Deployment Gift for Him, Anniversary Gift, Boyfriend Gift, Husband Gift - WC02', '16'),
    (9, 3, 'Gift for Dad, Co-Worker, ', '514Ps5Sj4sL._AC_US160_.jpg', 'Good Day, Bad Day - Funny 11 oz Rocks Glass, Permanently Etched, Gift for Dad, Co-Worker, Friend, Boss, Christmas - RG13', '15'),
    (10, 3, 'home stemless wine glass', '416MiOq22OL._AC_US160_.jpg', 'It''s not really drinking alone if the cat is home stemless wine glass, 15 oz.(cat) - Laser Etched', '12'),
    (11, 3, 'Party Glitter Paper Cake Topper', '51c-eFDruIL._AC_US160_.jpg', 'Personalized Congrats 2018 Graduation Party Glitter Paper Cake Topper', '13'),
    (12, 3, 'Turkish Towel Monogrammed', '51nNshZc2iL._AC_US160_.jpg', 'Turkish Towel Monogrammed | Monogrammed Linens | Kitchen Linens | Personalized Gifts | Farmhouse Towel', '15'),
    (13, 3, 'Mother''s day gift', '51BQpk5SSDL._AC_US160_.jpg', 'Mother''s day gift, Custom made music box with a quote for Mom with your choice of color and song, perfect gift for Mom', '69'),
    (14, 4, 'Last Name Sign', '71sXm+WEjWL._AC_SX220_SY220_.jpg', 'Last Name Sign with Wedding Date - Personalized Wedding Decor', '24'),
    (15, 4, 'Secured Lockable Card Box', '91x5k3DGehL._AC_SX220_SY220_.jpg', 'Secured Lockable Card Box with Card Slit - Rustic Wedding Card Box - Wedding Card Holder - Personalized Wedding Keepsake Box - Love Letter Box', '49'),
    (16, 4, 'Gold Bar Bracelet Handmade', '71Kk7haKFEL._AC_SX220_SY220_.jpg', 'Same Day Shipping before 12PM Personalized Name Plate Gold Bar Bracelet Handmade Bridesmaid gifts Anniversary for Mother best friend gifts for mom christmas gift for women - 12BR', '17'),
    (17, 4, 'Rustic Wedding Ceremony Sign', '61qV82XfaeL._AC_SX220_SY220_.jpg', 'Rustic Wedding Ceremony Sign, Rustic Wedding Decor, Rustic Wedding Signs, Bohemian Wedding Print only Frame not included', '12'),
    (18, 4, 'Wood Flower Box', '81B5q1iRxmL._AC_SX220_SY220_.jpg', 'You Are My Greatest Adventure Flower Vase - Planter Vase - Wood Flower Box - Wedding Centerpiece - Wooden Planter Box - Rustic Home Decor', '15'),
    (19, 4, 'Groomsmen Flasks Gift', '91JkAGk-32L._AC_SX220_SY220_.jpg', 'Personalized Flask - Real Wood Groomsmen Flasks Gift, Birthday Flask, 6oz Stainless Steel Wooden Flask Engraved - Best Man Gift Custom Engraved Flask, Monogram Groomsman Flask - Wedding Party Gift', '27'),
    (20, 6, 'Stacking Rings - Matte', '51wGeds9DCL._AC_US160_.jpg', 'Personalized Stackable Name Ring - Stacking Rings - Matte, Shiny, Rose Gold, Gold and Coffee Colors - 3mm Width', '14'),
    (21, 6, 'Plate Bar Gold Necklace Custom Silver', '51OzSXGjyhL._AC_US160_.jpg', 'Personalized Necklace Name Plate Bar Gold Necklace Custom Silver Necklace Wedding Bridesmaid Gift Mom Mother''s Day Gifts for Her - 4N', '18'),
    (22, 6, ' Gold Bar Necklace MOM', '51y+BTNG+TL._AC_US160_.jpg', 'Personalised Gold Bar Necklace MOM, MOMMY, MOTHER, MUM, MUMMY, MAMA or MAMMA for Mother''s Day or Birthday', '48'),
    (23, 6, 'Children 1st Birthday Great ', '41q-Q4Zz+4L._AC_US160_.jpg', 'SAME DAY SHIPPING TIL 2PM CDT A Baby Name Bar id Bracelet 16k Gold Plated Dainty Hand Stamp Artisan Bracelet Personalized Your Baby Name Customized New Born to Children 1st Birthday Great', '19'),
    (24, 5, 'APPLE MAGIC KEYBOARD', 'mla22za-2.jpg', ' APPLE MAGIC KEYBOARD (MLA22ZA/A, MLA22LL/A) ', '10,000 '),
    (25, 5, 'Apple Macbook Pro', 'mptt2ll-3.jpg', ' Apple Macbook Pro (2017) Quad-Core Intel Core i7 (2.9-3.9GHz, 16GB of 2133MHz LPDDR3 onboard memory, 512GB PCIe-Based Onboard SSD) 4GB Radeon Pro 560 Graphics, Touch Bar & Touch ID, 15.4 Inch Retina, Space Gray Macbook (MPTT2LL/A) ', '2445 '),
    (26, 5, 'Apple Macbook Pro', 'apple-macbook-pro-mid-2017-s-3_1.jpg', ' Apple Macbook Pro (2016) Intel Core i5 (2.0GHz,8GB,256GB SSD) 13.3 Inch Display Silver Notebook (MLUQ2ZA/A, MLUQ2LL/A) ', '2134'),
    (27, 5, 'HP ENVY 13-AD104TU', '13-ad042tx-silk-gold-3_1.jpg', ' HP ENVY 13-AD104TU 8th Gen Intel Quad Core i7 8550U (1.8-4.0GHz, 8GB LPDDR3 1866 Onboard, 256GB PCIe NVMe M.2 SSD) 13.3 Inch FHD IPS BrightView micro-edge WLED-Backlit Display (1920 x 1080) Golden Notebook with Win-10Home (2 Yr Warranty) #2LS86PA ', '9105');
    
    -- --------------------------------------------------------
    
    --
    -- Table structure for table `tbl_product_cat`
    --
    
    CREATE TABLE `tbl_product_cat` (
      `pd_cat_id` int(11) NOT NULL,
      `pd_cat_name` varchar(255) NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    
    --
    -- Dumping data for table `tbl_product_cat`
    --
    
    INSERT INTO `tbl_product_cat` (`pd_cat_id`, `pd_cat_name`) VALUES
    (3, 'Home & Kitchen'),
    (4, 'WEDDING'),
    (5, 'Electronics & Computers'),
    (6, 'Jewelry');
    
    --
    -- Indexes for dumped tables
    --
    
    --
    -- Indexes for table `tbl_cart`
    --
    ALTER TABLE `tbl_cart`
      ADD PRIMARY KEY (`cart_id`);
    
    --
    -- Indexes for table `tbl_customer`
    --
    ALTER TABLE `tbl_customer`
      ADD PRIMARY KEY (`c_id`);
    
    --
    -- Indexes for table `tbl_product`
    --
    ALTER TABLE `tbl_product`
      ADD PRIMARY KEY (`pd_id`);
    
    --
    -- Indexes for table `tbl_product_cat`
    --
    ALTER TABLE `tbl_product_cat`
      ADD PRIMARY KEY (`pd_cat_id`);
    
    --
    -- AUTO_INCREMENT for dumped tables
    --
    
    --
    -- AUTO_INCREMENT for table `tbl_cart`
    --
    ALTER TABLE `tbl_cart`
      MODIFY `cart_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=93;
    --
    -- AUTO_INCREMENT for table `tbl_customer`
    --
    ALTER TABLE `tbl_customer`
      MODIFY `c_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=29;
    --
    -- AUTO_INCREMENT for table `tbl_product`
    --
    ALTER TABLE `tbl_product`
      MODIFY `pd_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=28;
    --
    -- AUTO_INCREMENT for table `tbl_product_cat`
    --
    ALTER TABLE `tbl_product_cat`
      MODIFY `pd_cat_id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;
    /*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
    /*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
    /*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
    
    

    Browse by Category

    php Ajax jQuery Codeigniter html css javascript

    Hi there! I am Rayhan Mondol, a PHP & JAVA Developer and ICT task is my programming blog. I'm fond of developing modern web applications. Contact me, I accept the paid task

    Latest Article

    post thumbnail

    Ajax Shopping Cart Customer Order View & account Update by using PHP OOP PDO(E-Commerce website-part 10)

    post thumbnail

    customer accout logout by using PHP OOP, PDO,COOKIE,AJAX(E-Commerce website-part 9)

    post thumbnail

    Customer Account Login by using PHP OOP PDO,AJAX (E-Commerce website-part 8)

    post thumbnail

    Customer Account Create by using PHP OOP PDO (E-Commerce website-part 7)

    post thumbnail

    Remove product from cart by using PHP OOP PDO(E-Commerce website-part 6)

    post thumbnail

    Ajax Shopping Cart update or Edit by using PHP OOP PDO (E-Commerce website-part 5)

    post thumbnail

    Ajax Shopping Cart View and calculate by using PHP OOP PDO (E-Commerce website-part 4)

    post thumbnail

    Drag and Drop Product Add to Cart by using PHP OOP PDO Ajax Jquery - E-Commerce project- (part-3)

    post thumbnail

    Product Add to Cart using PHP OOP PDO Ajax JQuery - E-Commerce project- (part-2)

    post thumbnail

    Create Dynamic Tabs using PHP OOP PDO - E-Commerce project- (part-1)

    post thumbnail

    CodeIgniter AJAX CRUD using Bootstrap Modal - Delete

    post thumbnail

    CodeIgniter AJAX CRUD using Bootstrap Modal Edit or Update

    post thumbnail

    CodeIgniter AJAX CRUD using Bootstrap Modal Read or view

    post thumbnail

    CodeIgniter AJAX CRUD using Bootstrap Modal-Create

    post thumbnail

    CodeIgniter AJAX CRUD(setup removing index.php from url)