iemand een mening hier over ? ( ben pas 3 dagen bezig met php dus sorry voor domme vragen )er zitten nog wat gebreken in maar dit is me voornaamste probleem
kunt het werkend zien op http://www.unlimited-trading.nl/index.php
hier is mijn script
index.php
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<?php
require 'cart.php';
?>
<div class="container"><!-- start container -->
<div class="sixteen columns">
<h1 class="remove-bottom" style="margin-top: 40px">Test Shpping Cart </h1>
<hr />
</div>
<div id="products" class="two-thirds column">
<h1>Products In Our Store</h1>
<?php
echo products();
?>
</div>
<div id="shoppingcart" class="one-third column">
<h3>Your Cart</h3>
<?php
echo cart();
echo cart_qty();
?>
<br>
<br>
<br>hoeveel producten
</div></div><!-- end container -->
</body>
</html>
cart.php
<?php
// Start the session
session_start;
//session_destroy();
//error_reporting(0);
//heb ik veranderd//
$page = 'index.php';
//heb ik veranderd//
mysql_connect('localhost', 'unlimi1q_user', '****') or die(mysql_error());
mysql_select_db('unlimi1q_webshop') or die(mysql_error());
// heb deze array zelf geplaatst//
$_SESSION = array();
// add item to cart
if (isset($_GET['add'])) {
$quantity = mysql_query('SELECT id, quantity FROM Tblproducts WHERE id=' . mysql_real_escape_string((int)$_GET['add'])); //prevents SQL injections
while($quantity_row = mysql_fetch_assoc($quantity)) {
if($quantity_row['quantity'] != $_SESSION['cart_' . (int)$_GET['add']]) {
$_SESSION['cart_' . (int)$_GET['add']] += '1';
}
}
header('Location: ' . $page);
}
// remove one item from cart
if (isset($_GET['remove'])) {
$_SESSION['cart_' . (int)$_GET['remove']] --;
header('Location: ' . $page);
}
// delete item item from cart
if (isset($_GET['delete'])) {
$_SESSION['cart_' . (int)$_GET['delete']] = '0';
header('Location: ' . $page);
}
// display list of products
function products() {
$get = mysql_query('SELECT id, name, description, price FROM Tblproducts WHERE quantity > 0 ORDER BY id ASC');
if (mysql_num_rows($get) ==0) {
echo 'There are no products to display!';
} else {
while($get_row = mysql_fetch_assoc($get)) {
echo '<p>' . $get_row['name'] . '<br>' . $get_row['description'] . '<br>' . number_format($get_row['price'], 2) . '<br>' . '<br><a href="index.php?add=' . $get_row['id'] . '">Add</a></p>';
}
}
}
//display how many items are in the cart
function cart() {
foreach($_SESSION as $name => $value) {
if($value>0) {
if(substr($name, 0, 5) == 'cart_') {
//get exact number after "'cart_'$id"
$id = substr($name, 5, (strlen($name)-5));
//echo $id;
$get = mysql_query('SELECT id, name, price FROM Tblproducts WHERE id=' . mysql_real_escape_string((int)$id)); //prevents SQL injections
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="index.php?remove=' . $id .'">-</a> <a href="index.php?add=' . $id .'">+</a> <a href="index.php?delete=' . $id .'">delete</a><br>';
}
}
$total += number_format($sub, 2);
}
}
if ($total == 0) {
echo "Your cart is empty.";
}
else {
echo 'Total: € ' . number_format($total, 2) . '';
?>
<?php
}
}
function cart_qty(){
///how many items are in cart
}
?>