yep
<?php
session_start();
$page = "index.php";
mysql_connect("localhost","root","") or die(mysql_error());
mysql_select_db("ta2cart") or die(mysql_error());
if(isset($_GET['add'])) {
$quantity = mysql_query('SELECT id, quantity FROM products WHERE id='.mysql_real_escape_string((int)$_GET['add'])) or die(mysql_error());
while($quantity_row = mysql_fetch_assoc($quantity)) {
if($quantity_row['quantity']!=$_SESSION['cart_'.(int)$_GET['add']]) {
$_SESSION['cart_'.(int)$_GET['add']]+='1';
}
}
}
function products() {
$get = mysql_query('SELECT id, name, description, price FROM products WHERE quantity > 0 ORDER BY id DESC') or die(mysql_error());
if(mysql_num_rows($get)==0) {
echo "There are no products to display!";
}
else {
while($get_row = mysql_fetch_assoc($get)) {
echo'<p><b>'.$get_row['name'].'</b><br/>'.$get_row['description'].'<br/>'.number_format($get_row['price'],2).'€ <a href="cart.php?add='.$get_row['id'].'">Add</a><p/>';
}
}
}
function cart() {
foreach($_SESSION as $name => $value) {
if($value>0) {
if(substr($name, 0, 5)=='cart_') {
$id = substr($name, 5, (strlen($name)-5));
$get = mysql_query('SELECT id, name, price FROM products WHERE id='.mysql_real_escape_string((int)$id));
while($get_row = mysql_fetch_assoc($get)) {
$sub = $get_row['price']*$value;
echo $get_row['name'].' x '.$value.' @ '.number_format($get_row['price'], 2).'€ = '.number_format($sub, 2).'€'.' <a href=\'cart.php?remove='.$id.'\'>[-]</a> <a href=\'\'>[+]</a> <a href=\'\'>[Delete]</a><br/>'
}
}
}
else {
echo "Your cart is empty.";
}
}
}
?>
it is form alex's tutorial about the mini shopping cart.