http://perfectscents.zapto.org/perfectscents
All functions work and are linked with the mysql apart from checkout.
1) The table on createInvoice cannot display multiple items despite the cart displaying them perfectly.
2) The table also wont give me the total cost of purchase.
3) When and if you enter in details on createInvoice (which is unimportant) you are directed to completeInvoice where the following error messages are shown
Notice: Undefined offset: 2 in C:\wamp\www\perfectscents\invoice\completeInvoice.php on line 17
Notice: Undefined offset: 1 in C:\wamp\www\perfectscents\invoice\completeInvoice.php on line 17
Notice: Undefined variable: total in C:\wamp\www\perfectscents\invoice\completeInvoice.php on line 17
Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\perfectscents\invoice\completeInvoice.php on line 53
Below is the code for the php files
Look forward to some help and getting this coursework out the way
Thanks
TOM
Code: Select all
<?php # Script 13.9 - view_cart.php
// This page displays the contents of the shopping cart.
// Set the page title and include the HTML header.
$page_title = 'View Your Shopping Cart';
include_once ('header.html');
// Check if the form has been submitted (to update the cart).
if (isset ($_POST['submit'])) {
foreach ($_POST['qty'] as $key => $value) {
if ( ($value == 0) AND (is_numeric ($value)) ) {
unset ($_SESSION['cart'][$key]);
} elseif ( is_numeric ($value) AND ($value > 0) ) {
$_SESSION['cart'][$key] = $value;
}
}
}
// Check if the shopping cart is empty.
$empty = TRUE;
if (isset ($_SESSION['cart'])) {
foreach ($_SESSION['cart'] as $key => $value) {
if (isset($value)) {
$empty = FALSE;
}
}
}
// Display the cart if it's not empty.
if (!$empty) {
require_once ('mysql_connect.php'); // Connect to the database.
// Retrieve all of the information for the products in the cart.
$query = 'SELECT * FROM tblproducts WHERE tblproducts.product_id IN (';
foreach ($_SESSION['cart'] as $key => $value) {
$query .= $key . ',';
}
$query = substr ($query, 0, -1) . ') ORDER BY tblproducts.product_name ASC';
$result = mysql_query ($query);
// Create a table and a form.
echo '<table border="0" width="90%" cellspacing="3" cellpadding="3" align="center">
<tr>
<td align="left" width="30%"><b>Product</b></td>
<td align="right" width="10%"><b>Price</b></td>
<td align="center" width="10%"><b>Qty</b></td>
<td align="right" width="10%"><b>Total Price</b></td>
</tr>
<form action="view_cart.php" method="post">';
// Print each item.
$total = 0; // Total cost of the order.
while ($row = mysql_fetch_array ($result, MYSQL_ASSOC)) {
$drawInput= '<input type="hidden" name="items[]" value="'.$row['product_name'].'_'.$row['product_price'].'_'.$_SESSION['cart'][$row['product_id']].'" />';
// Calculate the total and sub-totals.
$subtotal = $_SESSION['cart'][$row['product_id']] * $row['product_price'];
$total += $subtotal;
// Print the row.
echo " <tr>
<td align=\"left\">{$row['product_name']}</td>
<td align=\"right\">£ {$row['product_price']}</td>
<td align=\"center\"><input type=\"text\" size=\"3\" name=\"qty[{$row['product_id']}]\" value=\"{$_SESSION['cart'][$row['product_id']]}\" /></td>
<td align=\"right\">£ " . number_format($subtotal, 2) ."</td>
</tr>\n";
} // End of the WHILE loop.
// Print the footer, close the table, and the form.
echo ' <tr>
<td colspan="4" align="right"><b>Total:<b></td>
<td align="right">£ ' . number_format($total, 2) .'</td>
</tr>
</table><div align="center"><input type="submit" name="submit" value="Update My Cart" />
</form><br /><br /><form method="post" action="invoice/createInvoice.php">'.$drawInput.'<input type="submit" value="Checkout"/></form></div>';
mysql_close($dbc); // Close the database connection.
} else {
echo '<p>Your cart is currently empty.</p>';
}
iclude_once ('footer.html'); // Require the HTML footer.
?>
<?
print_r ($_POST['items']);
?>
<h1>Thanks for Ordering.. Please enter your contact and billing details</h1>
<table width="800px">
<tr style="background-color:grey">
<th width="60%">Product Name</th><th width="20%" style="text-align:center">Price</th><th width="20%" style="text-align:center">Qty</th>
</tr>
<?php
$total=0;
if(isset($_POST)){
$itemAry=$_POST['items'];
foreach($itemAry as $val){
$valSplit=explode('_',$val);
$total=$total+intval($valSplit[2])*intval($valSplit[1]);
?>
<tr>
<?php
foreach($valSplit as $val){
print '<td>'.$val.'</td>';
}
?>
</tr>
<?php
}
}
?>
<tr>
<td colspan="2" style="text-align:right">Giving a subtotal of: </td><td style="text-align:center" > <? = $total ?> </td>
</tr>
</table>
<form action='./completeInvoice.php' method='POST'>
<br>
<b> Delivery Address </b>
<br>
<br>
<pre>Name: <input type=text name='Name' size=50> Email: <input type=text name='eMail' size=50></pre>
<br>
<pre>Address: <input type=text name='Address' size=50></pre>
<pre>Address: <input type=text name='Address1' size=50></pre>
<pre>Town: <input type=text name='Town' size=50></pre>
<pre>County: <input type=text name='County' size=30></pre>
<pre>Post Code: <input type=text name='PostCode' size=10></pre>
<pre>Country: <input type=text name='Country' size=30></pre>
<br>
<br>
<b> Cardholder Details </b>
<br>
<br>
<pre>Name: <input type=text name='Name1' size=50></pre>
<pre>Address: <input type=text name='Address3' size=50></pre>
<pre>Address: <input type=text name='Address4' size=50></pre>
<pre>Town: <input type=text name='Town2' size=50></pre>
<pre>County: <input type=text name='County2' size=30></pre>
<pre>Post Code: <input type=text name='Post Code2' size=10></pre>
<pre>Country: <input type=text name='Country2' size=30></pre>
<pre>Telephone: <input type=text name='Telephone2' size=15> Mobile: <input type=text name='Mobile' size=15></pre>
<pre>D of B: <input type=text name='Date of Birth' size=2><input type=text name='Date of Birth' size=2><input type=text name='Date of Birth' size=4> (eg 12/09/1957)</pre>
<br>
<br>
<b> Credit / Debit Card Details </b>
<br>
<br>
<pre>Card Number: <input type=text name='Card Number' size=18></pre>
<pre>Valid From: <input type=text name='Valid From' size=03><input type=text name='Valid From' size=02> ( eg APR/09 )</pre>
<pre>Expiry Date: <input type=text name='Expiry Date' size=03><input type=text name='Expiry Date' size=02> ( eg NOV/12 )</pre>
<pre>CV2 Number: <input type=text name='CV2' size=03></pre><p class=MsoNormal><span lang=EN-GB style='font-size:9.0pt;line-height:115%;
font-family:Arial'>Your card’s CV2 number is the <strong><span
style='font-family:Arial'>rightmost three digits</span></strong> printed on the
signature strip. We do not store your CV2 number, but use it to perform a <strong><span
style='font-family:Arial'>security check</span></strong> when you change your
credit/debit card details in any way.</span></p>
<br>
<br>
<?php
foreach($itemAry as $val){
?>
<input type=hidden name='items[]' value="<?=$val?>">
<?php
}
?>
<input type=submit value='Confirm Order'>
<?php
$to = $_POST['eMail'].", k0716026@kingston.ac.uk";//replace somebodyelse@example.com to yours
$subject = "invoice";
// BOF EMAIL CONTENT
$message = "
<h1>Thanks for Ordering with us//put your logo image here if you wish</h1>
<table width=\"800px\">
<tr style=\"background-color:grey\">
<th width=\"60%\">Product Name</th><th width=\"20%\" style=\"text-align:center\">Price</th><th width=\"20%\" style=\"text-align:center\">Qty</th>
</tr>";
if(isset($_POST)){
$itemAry=$_POST['items'];
foreach($itemAry as $key=>$val){
$valSplit=explode('_',$val);
$total=$total+$valSplit[2]*$valSplit[1];
$message .= "<tr>";
foreach($valSplit as $val){
$message .= '<td>'.$val.'</td>';
}
$message .="</tr>";
}
}
$message .="<tr>
<td colspan=\"2\" style=\"text-align:right\">subtotal of: </td><td style=\"text-align:center\" >".$total."</td>
</tr>
</table>";
$message .="<h3>Delivery address </h3><br/>";
$message .="
<br>
<br>
<pre>Name: ".$_POST['Name']."</pre>
<br>
<pre>Address: ".$_POST['Address']."</pre>
<pre>Address: ".$_POST['Address1']."</pre>
<pre>Town: ".$_POST['Town']."</pre>
<pre>County: ".$_POST['County']."</pre>
<pre>Post Code: ".$_POST['PostCode']."</pre>
<pre>Country: ".$_POST['Country']."</pre>
";
$message .="if you wish to say something about our webstie, replace here with your own words";
// EOF EMAIL CONTENT
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <k0716026@kingston.ac.uk>' . "\r\n";//change the address to yours
$headers .= 'Cc:'.$_POST['eMail']. "\r\n";//change the forwarding email address here
mail($to,$subject,$message,$headers);
?>
<html>
<head>
<title>Order Complete</title>
</head>
<body>
<table cellspacing=2 cellpadding=2 border=0 width=600>
<tr>
<td>
<br>
<center>
<img src="http://localhost/perfectscents/thx.jpg"></b></font></center>
<center>
<p>Thank You <b> <?=$_POST['Name'] ?> </b> for Ordering with us <br>
<br>
<a href="http://localhost/perfectscents/home.html">Go back to home page</a>
</b>
</font></center>
</td>
</tr>
</table>
</body>
</html>