Yes yes ... kommer her:
Dette er en af mine sider hvorfra du kan vælge en vare:
**jeans.php**
<?php
// Include MySQL class
require_once('cart/inc/mysql.class.php');
// Include database connection
require_once('cart/inc/global.inc.php');
// Include functions
require_once('cart/inc/functions.inc.php');
// Start the session
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"
http://www.w3.org/TR/html4/loose.dtd"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>LUXundPUNK - Jeans</title>
<link rel="stylesheet" type="text/css" href="mystyle2.css" />
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
<![endif]-->
</head>
<body>
<div id="home2">
<div id="lpshop">
<p class="style11">Jeans <form action="index.php" method="submit"><button type="submit">Tilbage til forretning</button></form></p>
</div>
<div id="kurv"><?php echo writeShoppingCart(); ?></div><br>
<div id="del">
<?php
$sql = 'SELECT * FROM toej2 WHERE del = "Jeans" AND lager > 0 ORDER BY id';
$result = $db->query($sql);
while ($row = $result->fetch()) {
$output[] = '<table border=1 cellpadding=1 cellspacing=0 borderColor=black>';
$output[] = '<tr>';
$output[] = '<td width=50px><p align="center" class="style12">'.$row['del'].'</p></td>';
$output[] = '<td width=100px><p class="style12">Mærke:<br>'.$row['maerke'].'</p></td>';
$output[] = '<td width=100px><p class="style12">Model:<br>'.$row['model'].'</p></td>';
$output[] = '<td width=70px><p class="style12">Størrelse:<br>'.$row['str'].'</p></td>';
$output[] = '<td width=40px><img src="../pics/thumb'.$row['pic'].'.jpg"></td>';
$output[] = '<td width=90px><p class="style12">Kr: '.$row['pris'] = number_format($row['pris'], 2, ",", ".").'</p></td>';
$output[] = '<td><a href="cart/cart.php?action=add&id='.$row['id'].'"><img src="../indkoebskurv.gif" border="0"></a></td>';
$output[] = '</tr>';
$output[] = '</table><br>';
}
echo join('',$output);
?>
</div>
</div>
</body>
</html>
****
Den kalder så denne her side som smider det i kurven:
**cart.php**
<?php
// Include MySQL class
require_once('inc/mysql.class.php');
// Include database connection
require_once('inc/global.inc.php');
// Include functions
require_once('inc/functions.inc.php');
// Start the session
session_start();
// Process actions
$cart = $_SESSION['cart'];
$action = $_GET['action'];
switch ($action) {
case 'add':
if(is_numeric($_GET['id'])) //Er ID et nummer?
{
$id = intval($_GET['id']);
$qty = $_GET['qty'];
$query = mysql_query("SELECT id FROM toej2 WHERE lager > 0 AND id = ".$id." LIMIT 1");
if(mysql_num_rows($query)==0) //Fandt vi varen og der er ingen på lager?
{
header( "location: ../minusvare.php" );
exit;
}else{
if ($cart) {
$cart .= ','.$_GET['id'];
} else {
$cart = $_GET['id'];
}
}
}
break;
case 'delete':
if(is_numeric($_GET['id'])) //Er ID et nummer?
{
$id = intval($_GET['id']);
$qty = $_GET['qty'];
$query = mysql_query("SELECT id FROM toej2 WHERE id = ".$id." LIMIT 1");
if(mysql_num_rows($query)==1)
{
if ($cart) {
$items = explode(',',$cart);
$newcart = '';
foreach ($items as $item) {
if ($_GET['id'] != $item) {
if ($newcart != '') {
$newcart .= ','.$item;
} else {
$newcart = $item;
}
}
}
$cart = $newcart;
}
}
}
break;
}
$_SESSION['cart'] = $cart;
header("location:" . $_SERVER['HTTP_REFERER']);
?>
****
Og denne her side viser kurven:
**indkobskurv.php**
<?php
// Include MySQL class
require_once('cart/inc/mysql.class.php');
// Include database connection
require_once('cart/inc/global.inc.php');
// Include functions
require_once('cart/inc/functions.inc.php');
// Start the session
session_start();
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"
http://www.w3.org/TR/html4/loose.dtd"><html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>LUXundPUNK - Din indkøbskurv</title>
<link rel="stylesheet" type="text/css" href="mystyle2.css" />
<!--[if IE]>
<link rel="stylesheet" type="text/css" href="mystyle.css" />
<![endif]-->
</head>
<body>
<div id="home2">
<div id="lpshop">
<p class="style11">Indkøbskurv</p>
</div>
<div id="del">
<?php
echo showCart();
?></div>
</div>
</body>
</html>
Her er så funktionerne til kurven:
**functions.inc.php**
<?php
function writeShoppingCart() {
$cart = $_SESSION['cart'];
if (!$cart) {
return '<p class="style12"><img src="../../indkoebskurv.gif"> er tom</p>';
} else {
// Parse the cart session variable
$items = explode(',',$cart);
$s = (count($items) > 1) ? 's':'';
return '<p class="style12">'.count($items).' ting i <a href="indkobskurv.php"><img src="../../indkoebskurv.gif" border="0"></a></p>';
}
}
function showCart() {
global $db;
$cart = $_SESSION['cart'];
if ($cart) {
$items = explode(',',$cart);
$contents = array();
foreach ($items as $item) {
$contents[$item] = (isset($contents[$item])) ? $contents[$item] + 1 : 1;
}
$output[] = '<form action="cart/cart.php?action=update" method="post" id="cart">';
$output[] = '<table border=1 cellspacing=0 borderColor=black>';
foreach ($contents as $id=>$qty) {
$sql = 'SELECT * FROM toej2 WHERE id = '.$id;
$result = $db->query($sql);
$row = $result->fetch();
extract($row);
$output[] = '<tr>';
$output[] = '<td><a href="cart/cart.php?action=delete&id='.$id.'&qty='.$qty.'" class="r">
<img src="../../indkoebskurv2.gif" border="0"></a></td>';
$output[] = '<td width=50px><p align="center" class="style12">'.$del.'</p></td>';
$output[] = '<td width=100px><p class="style12">Mærke:<br> '.$maerke.'</p></td>';
$output[] = '<td width=100px><p class="style12">Model:<br> '.$model.'</p></td>';
$output[] = '<td width=70px><p class="style12">Størrelse:<br> '.$str.'</p></td>';
$output[] = '<td width=90px><p class="style12">Kr '.number_format($pris, 2, ",", ".").'</p></td>';
$output[] = '<td width=10px><input type="text" name="qty'.$id.'" value="'.$qty.'" size="1" maxlength="1" /></td>';
$output[] = '<td width=110px><p class="style12">Kr '.number_format($pris * $qty, 2, ",", ".").'</p></td>';
$total += $pris * $qty;
$output[] = '</tr>';
}
$output[] = '</table>';
$output[] = '<br><p class="style12">I alt: <strong>Kr: '.number_format($total, 2, ",", ".").'</strong></p>';
$output[] = '<div><button type="submit">Opdater indkøbskurv</button></div>';
$output[] = '</form>';
$output[] = '<FORM><INPUT TYPE="button" VALUE="Tilbage" onClick="history.go(-1);return true;"></FORM>';
} else {
$output[] = '<p class="style12">Indkøbskurven er tom.</p><br><FORM><INPUT TYPE="button" VALUE="Tilbage" onClick="history.go(-1);return true;"></FORM>';
}
return join('',$output);
}
?>
****
Siden hvor du skriver adresse osv...:
**sluthandel.php**
<?php
// Include MySQL class
require_once('cart/inc/mysql.class.php');
// Include database connection
require_once('cart/inc/global.inc.php');
// Include functions
require_once('cart/inc/functions.inc.php');
// Start the session
session_start();
?>
<?php
echo writeShoppingCart();
?>
<?php
$id = intval($_GET['id']);
$id = intval($_GET['qty']);
$output[] = '<form action="submitorder.php" method="post">';
$output[] = '<table border=1 cellspacing=0 borderColor=black>';
$output[] = '<tr>';
$output[] = '<td>Fornavn:<br>
<input type="text" name="fornavn" style="width: 200px;"><br></td>';
$output[] = '</tr>';
$output[] = '<tr>';
$output[] = '<td>Efternavn:<br>
<input type="text" name="efternavn" style="width: 200px;"><br></td>';
$output[] = '</tr>';
$output[] = '<tr>';
$output[] = '<td>Vejnavn og nr evt sal osv..:<br>
<input type="text" name="vejnavn" style="width: 300px;"><br></td>';
$output[] = '</tr>';
$output[] = '<tr>';
$output[] = '<td>Postnr og by:<br>
<input type="text" name="postbynavn" style="width: 300px;"><br></td>';
$output[] = '<tr>';
$output[] = '</tr>';
$output[] = '<td>Telefonnr:<br>
<input type="text" name="telenavn" style="width: 200px;"><br></td>';
$output[] = '</tr>';
$output[] = '<tr>';
$output[] = '<td>E-mail:<br>
<input type="text" name="email" style="width: 300px;"><br></td>';
$output[] = '</tr>';
$output[] = '<tr>';
$output[] = '<td><input type="submit" value="Betal/send ordre"></td>';
$output[] = '</tr>';
$output[] = '</table>';
$output[] = '</form>';
echo join('',$output);
****
Og endelig min submit der skulle sende mailen:
**submitorder.php**
<?php
// Include MySQL class
require_once('cart/inc/mysql.class.php');
// Include database connection
require_once('cart/inc/global.inc.php');
// Include functions
require_once('cart/inc/functions.inc.php');
// Start the session
session_start();
// Process actions
if (isset($_POST['fornavn']) && isset($_POST['efternavn']) && isset($_POST['vejnavn'])
&& isset($_POST['postbynavn']) && isset($_POST['telenavn']) && isset($_POST['email']))
{
if (empty($_POST['fornavn']))
{
echo "Du skal indtaste dit fornavn.";
}
elseif (empty($_POST['efternavn']))
{
echo "Du skal indtaste dit efternavn.";
}
elseif (empty($_POST['vejnavn']))
{
echo "Du skal indtaste vejnavn og nr.";
}
elseif (empty($_POST['postbynavn']))
{
echo "Du skal indtaste postnr og by.";
}
elseif (empty($_POST['telenavn']))
{
echo "Du skal indtaste telefonnummer.";
}
elseif (empty($_POST['email']))
{
echo "Du skal indtaste din e-mail.";
}
else
{
$modtager = "min@timhs.dk";
$emne = "Bestilling fra hjemmesiden";
$besked = "Bestille fra hjemmesiden: \n
Fornavn: " . $_POST['fornavn']. "\n
Efternavn: " . $_POST['efternavn']. "\n
Vejnavn: " . $_POST['vejnavn']. "\n
Postnr & by: " . $_POST['postbynavn']. "\n
E-mail: " . $_POST['email'];
$header = "from:afs@afsender.dk";
mail($modtager, $emne, $besked, $header);
echo "Bestilling modtaget";
}
}
?>
<Html>
<Head>
</Head>
<Body>
<FORM METHOD="LINK" ACTION="../index.php"><INPUT TYPE="submit" VALUE="OK"></FORM>
</Body>
</Html>
***
Så jeg regnede med at det var et eller andet i submit order jeg skulle gøre ?