26. september 2005 - 13:46
Der er
8 kommentarer og
1 løsning
php mail: send indhold af indkøbskurv til mail
På det site jeg er ved at lave er der en indkøbskurv, som forhåbentlig bliver fyldt med varer... Der er ikke noget betalings system på siden. Indholdet af indkøbskurven skal derfor bare sendes til sælgeren og en bekræftelse skal sendes til køberen.
Er der nogen der kan hjælpe mig her?
Indkøbskurven kan f.eks. være fyldt således:
http://www.triodimenzionale.dk/misc/mailphp.jpgHver vare har så følgende parametre der skal følge med: itemName, itemType, itemQty, itemPrice,.. derudover skal total prisen jo oxo gerne med.
Håber nogen kan hjælpe
/Snig
26. september 2005 - 14:15
#1
Giv hver <select> et ID der afspejler varen - fx det vare-id som den har i databasen:
<select name="213" id="213">
<option value="1">1</option>
<option value="2">2</option>
</select>
..osv for hver vare. Når brugeren så trykker "Bestil", kan du i din forms action-script SELECT'e de informationer du skal bruge om hver vare, som du skal bruge; altså itemName, itemType, itemQty, itemPrice osv..
For at sende mails kan du bruge mail() funktionen.
26. september 2005 - 14:19
#2
Altså eksempelvis:
$sql = "SELECT ID, itemName, itemType, itemQty, itemPrice FROM product_table WHERE id='DIT-VARE-ID'";
26. september 2005 - 15:35
#6
yep det er rigtig de bliver hentet ind i en form fra en database...
En kammerat har oxo lige pointeret at jeg jo skal have tømt indkøbskurven når bestillingen er sendt,.. er det oxo meget besværligt at gøre?
Jeg smider lige koden til min cart.php her:
<?php
include("db.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>Jernbanemaerker.dk - Indkøbskurv</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css/styles.css" rel="stylesheet" type="text/css">
<script language="JavaScript">
function UpdateQty(item)
{
itemId = item.name;
newQty = item.options[item.selectedIndex].text;
document.location.href = 'cart.php?action=update_item&id='+itemId+'&qty='+newQty;
}
</script>
</head>
<body bgcolor="#D8C5A3">
<table width="900" border="0" align="center" cellpadding="0" cellspacing="0">
<tr align="right" valign="top">
<td width="900" height="143" class="top"><table width="555" height="138" border="0" cellpadding="0" cellspacing="0">
<tr>
<td align="left" valign="bottom"><a href="#">FORSIDE</a> | <a href="#">PRODUKTER</a> | <a href="#">KONTAKT</a> | <a href="#" class="style2">INDKØBSKURV</a></td>
</tr>
</table></td>
</tr>
<tr>
<td height="503" valign="top" class="body" bgcolor="#F2E3C8"><p> </p>
<form name="frmCart" method="get">
<table width="100%" cellspacing="0" cellpadding="0" border="0">
<tr class="text">
<td height="12"> </td>
<td width="37%" height="12">PRODUKT</td>
<td width="16%">VARETYPE</td>
<td height="12">ANTAL</td>
<td height="12">PRIS PR. STK.</td>
<td height="12">SLET VAREN?</td>
</tr>
<tr class="text">
<td height="13" colspan="6"><img src="gfx/prik.jpg" width="100%" height="1"></td>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
// Increment the total cost of all items
$totalCost += ($row["qty"] * $row["itemPrice"]);
?>
<tr class="text">
<td width="2%" height="25"> </td>
<td class="text"><?php echo $row["itemName"]; ?></td>
<td class="text"><?php echo $row["itemType"]; ?></td>
<td width="14%" height="25" class="text">
<select name="<?php echo $row["itemId"]; ?>" onChange="UpdateQty(this)">
<?php
//for($i = 1; $i <= 20; $i++)
for($i = 1; $i <= $row["itemQty"]; $i++)
{
echo "<option ";
if($row["qty"] == $i)
{
echo " SELECTED ";
}
echo ">" . $i . "</option>";
}
?>
</select>
</td>
<td width="19%" height="25">
KR.<?php echo " ".number_format($row["itemPrice"], 2, ".", ","); ?>
</td>
<td width="12%" height="25">
<a href="cart.php?action=remove_item&id=<?php echo $row["itemId"]; ?>" class="style2">SLET VAREN</a>
</td>
</tr>
<?php
}
// Display the total
?>
<tr class="text">
<td colspan="6"><img src="gfx/prik.jpg" width="100%" height="1"> </td>
</tr>
<tr class="text">
<td> </td>
<td colspan="2"> </td>
<td align="right">TOTAL: </td>
<td colspan="2"> KR.<b><?php echo " ".number_format($totalCost, 2, ".", ","); ?></b></td>
</tr>
<tr class="text">
<td> </td>
<td colspan="2"> </td>
<td align="right"> </td>
<td colspan="2"> </td>
</tr>
<tr class="text">
<td> </td>
<td colspan="2"><a href="products.php?mainId=101" class="style2"><< Keep Shopping</a></td>
<td align="right"> </td>
<td colspan="2">Send bestilling >> </td>
</tr>
</table>
</form>
</p></td>
</tr>
</table>
</body>
</html>
<?php
}
?>