I have an online foods store where members can pick what they want to buy and submit the cart content when done. below is the script
Code: Select all
$cartOutput =="";
$cartTotal =="";
if(!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"])<1){
$cartOutput = "<p> </p><p><h2 align='center'>Your Shopping Cart is empty.</p> <p></p></h2>";
}else{
$i = 0;
foreach($_SESSION["cart_array"] as $each_item){
$number++;
$item_id = $each_item["item_id"];
$sql = mysql_query("SELECT * FROM products WHERE hydee='$item_id' LIMIT 1");
$listing = 1;
while($roll=mysql_fetch_array($sql)){
$id=stripslashes($roll[hydee]);
$pid=stripslashes($roll[phydee]);
$product=stripslashes($roll[product]);
$type=stripslashes($roll[type]);
$name=stripslashes($roll[name]);
$facts=stripslashes($roll[facts]);
$detail=stripslashes($roll[detail]);
$ingredients=stripslashes($roll[ingredients]);
$how=stripslashes($roll[how]);
$price=stripslashes($roll[price]);
$qty=stripslashes($roll[qty]);
}
$totalPrice2 = $price * $each_item['quantity']; //price times quantity.
$cartTotal = $totalPrice2 + $cartTotal; //sum up all the prices in the cart to give grand amount.
//putting all prices into naira format.
$price = "#".number_format($price, '00','.',',').".00";
$totalPrice = "#".number_format($totalPrice2, '00','.',',').".00";
$get_imgs = mysql_query("SELECT * FROM product_imgs WHERE phydee='$pid' ORDER BY hydee asc LIMIT 1");
$rows = mysql_fetch_array($get_imgs);{
$spix = $rows[spix];
$bpix = $rows[bpix];
if($bpix!=""){
$pix = "adminpanel/imgs/products/$spix";
list($width, $height, $type, $attr) = getimagesize($pix);
if($width > $height) $size='100px';
else{
$new = 100 * $width;
$size = $new / $height;
$size = $size."px";}}}
if($type == 'Equipment') $img = "<img src='adminpanel/imgs/products/$facts' width='90' class='img_border' />";
elseif($spix!="") $img = "<img src='adminpanel/imgs/products/$spix' width='$size' class='img_border' />";
else $img = "<img src='images/product.png' width='80' class='img_border' />";
//location of product/equipment detail by segun
if($type == 'Equipment') $location = "equipment_detail.php?id=$id";
else $location = "product_detail.php?id=$id";
//dynamic rows assembly
$cartOutput.="<tr>";
$cartOutput.="<td align='center' valign='top' style='border-bottom:1px solid #ccc'>".$number."</td>";
$cartOutput.="<td align='center' valign='top' style='border-bottom:1px solid #ccc'><a href='$location'>$img<br/>".$name."</a></td>";
$cartOutput.="<td align='centre' valign='middle' style='border-bottom:1px solid #ccc'>".$price."</td>";
$cartOutput.="<td align='center' valign='middle' style='border-bottom:1px solid #ccc'>
<form action='cart.php' method='post'>
<input name='quantity' type='text' size='1' maxlength='2' value='".$each_item['quantity']."' />
<input name='adjustBtn".$item_id."' type='submit' value='Adjust' />
<input name='item_to_adjust' type='hidden' value='".$item_id."' />
</form></td>";
//$cartOutput.="<td align='center' valign='middle' style='border-bottom:1px solid #ccc'>".$each_item['quantity']."</td>";
$cartOutput.="<td align='centre' valign='middle' style='border-bottom:1px solid #ccc'>".$totalPrice."</td>";
$cartOutput.="<td align='right' valign='middle' style='border-bottom:1px solid #ccc'><form action='cart.php' method='post'><input name='deleteBtn".$item_id."' type='submit' value='Remove' /><input name='index_to_remove' type='hidden' value='".$i."' /></form></td>";
$cartOutput.="</tr>";
$i++;
//submit order into the database if the member click on SUBMIT MY ORDER in the Cart Page
$order = $_GET[order];
if($order!=""){
$order_id = $mid.$newunix;
$quantity = $each_item['quantity'];
$submit_order = mysql_query("INSERT INTO purchases (member_id, order_id, product, qty, price, totalamount, date, time, ip) VALUES ('$mid', '$order_id', '$id', '$quantity', '$totalPrice2', '$cartTotal', '$date', '$time', '$ip')");
}
//MAIL POSITION 1 (FOR SENDING MAIL TO THE MEMBER ON SUBMITTING THE CART)
}
//MAIL POSITION 2 (FOR SENDING MAIL TO THE MEMBER ON SUBMITTING THE CART)
}
Code: Select all
// To send HTML mail, the Content-type header must be set
if($order!=""){
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Food & Beverages Ltd <info@foods.com>' . "\r\n";
$to = $memail;
$subject = "Your Order is received (Orider ID: $order_id)";
//message to be sent begins
$message = "Hello ".$firstname."<br/><br/>Thank you for the interest in our Products. Your Order ID is $order_id and your order is as below<br/><br/>".$mailCart."<br/><br/>Thank you";
//message to be sent ends
mail($to, $subject, $message, $headers);
header("location:submit_order.php");
}
Please what is the right thing for me to do.