PHP Classes
elePHPant
Icontem

File: simple_mycart

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Fabio Mazzola  >  MyCart  >  simple_mycart  >  Download  
File: simple_mycart
Role: Example script
Content type: text/plain
Description: Simple My Cart
Class: MyCart
Manage a shopping cart stored in a MySQL database
Author: By
Last change:
Date: 8 years ago
Size: 1,536 bytes
 

Contents

Class file image Download
<?php

 
class cart{
 
  var
$user="root";
  var
$pass="";
  var
$host="localhost";
  var
$database="cart";
 
   function
conn()
    {
   
mysql_connect($this->host,$this->user,$this->pass)or die("non riesco a connettermi");
   
mysql_select_db("$this->database")or die("non riesco selezionare il database");
    }
   
   function
inscart($articolo, $qta)
   {
   
$SQL= "INSERT INTO cart (IDarticolo , Qta) VALUES ('$articolo', '$qta')";
   
mysql_query($SQL);
   }
  
   function
delcart($articolo)
   {
   
$SQLdel= "DELETE FROM cart WHERE IDarticolo = '$articolo'";
   
mysql_query($SQLdel);
   }
  
   function
conta()
   {
   
$SQL2= "SELECT IDarticolo, sum(qta) as somma from cart group by IDarticolo";
   
$query = mysql_query($SQL2);
   
$row_somma = mysql_fetch_assoc($query);
 
  do {
  print
'Hai ' . $row_somma['somma'] . ' pezzi nel carrello dell\' articolo ' . $row_somma['IDarticolo'];
  } while (
$row_somma = mysql_fetch_assoc($query));
   }
  
   function
close()
   {
  
mysql_close();
   }
  }
 
 
$mycart=new cart();
 
$mycart->conn();
 
$mycart->conta();
 
  if (isset(
$_REQUEST['ins']) && ($_REQUEST['ins'] == 1))
  {
 
$mycart->inscart($_REQUEST['item'], $_REQUEST['qta']);
  }
  
  if (isset(
$_REQUEST['del']) && ($_REQUEST['del'] == 2))
  {
 
$mycart->delcart($_REQUEST['itemdel']);
  }
 
 
$mycart->close();
 
?>
<!-- here change the par with your itemcode -->
<a href="test.php?ins=1&item=39&qta=1">Add to Cart</a>
<a href="test.php?del=2&itemdel=12">Remove to Cart</a>