checkout ting
Halløjsa har følgende checkout script til min online shop...Det som skal ske er at den skal sende info med de vare som ligger i <?php echo $row["id"]; ?><?php echo $row["itemName"]; ?> til en mail... det virker også sådan som det ser ud nu... men hvis der er flere end 2 vare så sender den kun den sidst addéd...
håber på en løsning...
------------checkout-------------
<?php
ob_start();
include("db.php");
global $dbServer, $dbUser, $dbPass, $dbName;
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$result = mysql_query("select * from cart inner join items on cart.itemId
= items.itemId where cart.cookieId = '". GetCartId() . "' order by
items.itemName asc");
?>
<html>
<body>
<form action="<?php echo $PHP_SELF; ?> " method="POST">
<? ob_start(); ?>
<?php
switch($_GET["action"])
{
case "add_item":
{
AddItem($_GET["id"], $_GET["qty"]);
ShowCart();
break;
}
case "update_item":
{
UpdateItem($_GET["id"], $_GET["qty"]);
ShowCart();
break;
}
case "remove_item":
{
RemoveItem($_GET["id"]);
ShowCart();
break;
}
default:
{
ShowCart();
}
}
function AddItem($itemId, $qty)
{
// Will check whether or not this item
// already exists in the cart table.
// If it does, the UpdateItem function
// will be called instead
global $dbServer, $dbUser, $dbPass, $dbName;
// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
// Check if this item already exists in the users cart table
$result = mysql_query("select count(*) from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");
$row = mysql_fetch_row($result);
$numRows = $row[0];
if($numRows == 0)
{
// This item doesn't exist in the users cart,
// we will add it with an insert query
@mysql_query("insert into cart(cookieId, itemId, qty) values('" . GetCartId() . "', $itemId, $qty)");
}
else
{
// This item already exists in the users cart,
// we will update it instead
UpdateItem($itemId, $qty);
}
}
function UpdateItem($itemId, $qty)
{
// Updates the quantity of an item in the users cart.
// If the qutnaity is zero, then RemoveItem will be
// called instead
global $dbServer, $dbUser, $dbPass, $dbName;
// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
if($qty == 0)
{
// Remove the item from the users cart
RemoveItem($itemId);
}
else
{
mysql_query("update cart set qty = $qty where cookieId = '" . GetCartId() . "' and itemId = $itemId");
}
}
function RemoveItem($itemId)
{
// Uses an SQL delete statement to remove an item from
// the users cart
global $dbServer, $dbUser, $dbPass, $dbName;
// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
mysql_query("delete from cart where cookieId = '" . GetCartId() . "' and itemId = $itemId");
}
function ShowCart()
{
// Gets each item from the cart table and display them in
// a tabulated format, as well as a final total for the cart
global $dbServer, $dbUser, $dbPass, $dbName;
// Get a connection to the database
$cxn = @ConnectToDb($dbServer, $dbUser, $dbPass, $dbName);
$totalCost = 0;
$result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . GetCartId() . "' order by items.itemName asc");
?>
<html>
<head>
<title> Your Shopping Cart </title>
<script language="JavaScript">
function UpdateQty(item)
{
itemId = item.name;
newQty = item.options[item.selectedIndex].text;
document.location.href = 'head-cart.php?action=update_item&id='+itemId+'&qty='+newQty;
}
</script>
<body bgcolor="#ffffff">
<form action="<?php echo $PHP_SELF; ?> " method="POST">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr>
<td width="15%" height="25">
<b>Pcs.</b></font>
</td>
<td width="55%" height="25">
<b>Product</b></font>
</td>
<td width="20%" height="25">
<b>Price</b></font>
</td>
<td width="10%" height="25"> </td>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
// Increment the total cost of all items
$totalCost += ($row["qty"] * $row["itemPrice"]);
?>
<tr>
<td width="15%" height="25">
<input name="qty" type="text" value=" <?php
echo $row["qty"]
?>" size="2" disabled>
</td>
<td width="55%" height="25">
<input type="text" name="vare" value="<?php echo $row["id"]; ?><?php echo $row["itemName"]; ?>" disabled>
</font>
</td>
<td width="20%" height="25">
<?php echo number_format($row["itemPrice"], 2, ".", ","); ?> Dkk
</font>
</td>
<td width="10%" height="25"> </td>
</tr>
<?php
}
// Display the total
?>
<tr>
<td width="100%" colspan="4">
<hr size="1" NOSHADE>
</td>
</tr>
<tr>
<td width="70%" colspan="2"> </td>
<td width="30%" colspan="2">
<b>Total: <?php echo number_format($totalCost, 2, ".", ","); ?> Dkk </b>
</font>
</td>
</tr>
</table>
</body>
</html>
<?php
}
?>
<? ob_end_flush(); ?>
<table width="455">
<tr>
<td width="25%">Navn:</td>
<td width="75%"> <input type="text" name="navn"> </td>
</tr>
<tr>
<td>Adresse:</td>
<td> <input type="text" name="adresse"> </td>
</tr>
<tr>
<td>Post nummer: </td>
<td> <input type="text" name="postnr"> </td>
</tr>
<tr>
<td>By:</td>
<td> <input type="text" name="by"> </td>
</tr>
<tr>
<td>Telefon:</td>
<td> <input type="text" name="telefon"> </td>
</tr>
<tr>
<td>E-Mail:</td>
<td> <input type="text" name="epost"> </td>
</tr>
</table>
<blockquote> <br>
Bemærkninger:<br>
<textarea wrap="on" class="but" rows="5" cols="30" name="tekst"></textarea>
<br>
<input type="submit" class="button" value="Send Ordre" name="send">
<br>
<?php
if ($send) {
function tilbage($meddelelse) {
echo "$meddelelse\n";
echo "<form><input type=button value=\"<<< Tilbage\" onClick=history.back()></form>\n";
echo "</body></html>\n";
exit;
}
if (!$navn) tilbage( "<BR><BR>Du har glemt at skrive dit navn...");
if (!$tekst) tilbage( "Du har glemt at skrive noget beskedfeltet");
$navn = "$navn ";
$adresse = "$adresse ";
$postnr = "$postnr ";
$by = "$by ";
$telefon = "$telefon ";
$epost = "$epost ";
$vare = "$vare ";
$qty = "$qty ";
mail( "yahoooo@c.dk", "Ordre fra - $navn", "$navn , $adresse, $postnr, $by, $telefon, $epost, $tekst, $vare, $qty", "From: $epost\nX-Mailer: http://$HTTP_HOST$REQUEST_URI");
echo "Vi har modtaget din bestilling, er varene bestilt inden kl 14:00 afsendes de idag.\n";
}
?>
</font> </div>
</blockquote>
</form>
</body></html>
<?php
ob_end_flush();
?>