Vil ikke sende info fra textfield!
Kan I finde ud af hvorfor den ikke gider sende informationen fra mine textfields?kode:
<?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;
}
case "confirm"://SEND MAIL
sendmail();
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 sendmail()
{
$conn = mysql_connect("localhost", "ftpside", "xtP0m2UQNE9NT0W");
mysql_select_db("ftpside");
$sql = "select ii.itemName as navn, ii.Size as size, tt.qty as antal, (ii.Size * tt.qty) as ialt from cart tt, items ii where tt.cookieId='".GetCartId(). "' and tt.itemId=ii.itemId";
$result = mysql_query($sql);
$content = "Request:\n";
while($row=mysql_fetch_array($result))
{
$content .= "From: $user\nEmail: $email\nName: ".$row[navn]."\nSize: ".$row[size]." mb\nTotal Size: ".$row[ialt]." mb\n";
}
mail("andreas@hansen.tdcadsl.dk","Request", $content);
header("location: send.php".$_SERVER[PHP_SELV]);
}
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 = 'cart.php?action=update_item&id='+itemId+'&qty='+newQty;
}
</script>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"></head>
<body bgcolor="#666666" text="#000000" link="#000000" vlink="#000000" alink="#000000">
<h1> </h1>
<form name="frmCart" method="get">
<p align="center"><strong>User:</strong><br>
<input name="user" type="text" id="user">
<br>
<strong>Email:</strong><br>
<input name="email" type="text" id="email">
</p>
<table width="37%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr bgcolor="#999999">
<td height="25" bgcolor="#999999">
<font face="verdana" size="1" color="#000000">
<b>Product</b>
</font> </td>
<td width="27%" height="25">
<font face="verdana" size="1" color="#000000">
<b>Size:</b></font>
</td>
<td width="29%" height="25" bgcolor="#999999">
<font face="verdana" size="1" color="#000000">
<b>Remove?</b>
</font>
</td>
</tr>
<?php
while($row = mysql_fetch_array($result))
{
// Increment the total cost of all items
$totalCost += ($row["qty"] * $row["Size"]);
?>
<tr>
<td height="25">
<font face="verdana" size="1" color="black">
<?php echo $row["itemName"]; ?>
</font> </td>
<td width="27%" height="25">
<font face="verdana" size="1" color="black"> <?php echo number_format($row["Size"], 2, ".", ","); ?>
</font>
</td>
<td width="29%" height="25">
<font face="verdana" size="1" color="black">
<a href="cart.php?action=remove_item&id=<?php echo $row["itemId"]; ?>">Remove</a>
</font>
</td>
</tr>
<?php
}
// Display the total
?>
<tr>
<td colspan="3"> </td>
</tr>
<tr>
<td width="44%">
<font face="verdana" size="1" color="black">
<a href="products.php"><< Keep Shopping</a>
</font>
</td>
<td colspan="2">
<p><font face="verdana" size="2" color="black">
<b>Total Size: <?php echo number_format($totalCost, 2, ".", ","); ?></b>
</font>
</p></td>
</tr>
</table>
<div align="center"></div>
<div align="center"></div>
<p align="center"><a href="cart.php?action=confirm"><strong>Confirm</strong></a></p>
</form>
</body>
</html>
<?php
}
?>
Det er funktionen sendmail() som sender emailen...
