Thats great to hear, looks like you got a lot done over the weekend.
I can explain the array thing for you
$input[] = array($row['itemId''],$row['itemName'],$row['qty']);
When you add values to an array, if you don't give them a key they are automatically assigned a numeric key starting from 0 eg . 0,1,2,3,4 . so for each item you are making an array with 3 values array(0=>itemid,1=>itemname,2=>qty)
so later on when you loop through all the items in $input ($input contains many arrays
eg. *
$input = array(
0=>array(0=>itemid,1=>itemname,2=>qty),
1=>array(0=>itemid,1=>itemname,2=>qty),
2=>array(0=>itemid,1=>itemname,2=>qty)
);*
hopefully it doesnt blow your mind trying to grasp that, so when we do foreach($input as $item)
in the example above $item will loop 3 times being entry 0,1 and 2 and have them 3 values available - also referenced as 0,1,2
foreach($input as $item){
$key = $item[0];
$name = $item[1];
$qty = $item[2];
if you ever want to add more data for the item just add it into the array:
$input[] = array($row['itemId'] ,$row['itemName'], $row['qty'], $row['img1'], $row['smalldesc']);
which will make $img1 = $item[3];$smalldesc = $item[4];
As for the final problem, the form opens on line 156 <form action="checkout2.php?" method="post">
is checkout2.php correct?
<input name="place" type="hidden" id="place" value="yes" />
<input name="tcost" type="hidden" id="tcost" value="<? echo $totalCost; ?>" />
<input name="ship" type="hidden" id="ship" value="<? echo $ship; ?>" />
<input name="taxx" type="hidden" id="taxx" value="<? echo $totalTax; ?>" />
<input type="submit" name="Submit" value="Place Order" />
$cartdata = listItems($input,$_POST['country'],$sstat);
$cartTotalCost = $cartdata['totalbill'];//total with tax and shipping, no gift wrap or express
$ship = $cartdata['shipping'];//shipping cost
$salesTotal = $cartdata['totalsales'];//sales cost, no tax or shipping
$totalTax = $cartdata['totaltax'];//tax
$noTaxShipTotal = $salesTotal + $express + $gift;//no tax/shipping total
$ordertotal = $cartTotalCost + $express + $gift;//full cost of sales,tax,shipping,gift and express
//----------store important values in session--------------//
$_SESSION['tcost'] = $noTaxShipTotal;//no tax or shipping
$_SESSION['ship'] = $ship;
$_SESSION['taxx'] = $totalTax;
//----------store important values in session--------------//
echo $cartdata['html']
Then theform should be updated to use the right variables: (if i got them right)
<input name="place" type="hidden" id="place" value="yes" />
<input name="tcost" type="hidden" id="tcost" value="<? echo $noTaxShipTotal; ?>" />
<input name="ship" type="hidden" id="ship" value="<? echo $ship; ?>" />
<input name="taxx" type="hidden" id="taxx" value="<? echo $totalTax; ?>" />
<input type="submit" name="Submit" value="Place Order" />
As for why the order is not submitting i've fixed the top up a bit, not that i could see much wrong - it's the section inside if (isset($_POST['place'])) {
that processes the order, i just added an extra error catch
<?php
session_start();
header("Cache-control: private");
require_once ('include/init.php');
require_once ('include/functions.php');
if (isset($_POST['ins'])) {
if (!isset($_POST['promo'])) {$promo="no";} else {$promo="yes";}
$sstat = $_POST["stat"];
$sql="INSERT INTO cust(fname, lname, email, addr, city, stat, zip, promo, phone, dt, country) VALUES (".
"'".mysql_real_escape_string(trim($_POST["fname"]))."', ".
"'".mysql_real_escape_string(trim($_POST["lname"]))."', ".
"'".mysql_real_escape_string(trim($_POST["email"]))."', ".
"'".mysql_real_escape_string(trim($_POST["addr"]))."', ".
"'".mysql_real_escape_string(trim($_POST["city"]))."', ".
"'".mysql_real_escape_string(trim($_POST["stat"]))."', ".
"'".mysql_real_escape_string(trim($_POST["zip"]))."', ".
"'".$promo."', ".
"'".mysql_real_escape_string(trim($_POST["phone"]))."',NOW(),'".trim(mysql_real_escape_string($_POST["country"]))."') ";
$rs= mysql_query($sql);
$uid = mysql_insert_id();
$_SESSION['uid'] = $uid;
$country = trim($_POST["country"]);
$_SESSION['country'] = trim($_POST["country"]);
if (mysql_affected_rows()<0){
print "<B>Fatal ERROR: Could not add customer.</B>";
exit();
}
}
if (isset($_POST['place'])) {
$sql="SELECT * from cust where id = ".mysql_real_escape_string($_SESSION['uid']);
$rs= mysql_query($sql) or die(mysql_error());
if($rs !== false){
$row=mysql_fetch_array($rs);
$eemail = $row["email"];
$country = $row["country"];
if ($_POST["express"] == "15"){$express = 15; $expyes = "yes";}else{$express = 0; $expyes = "no";}
if ($_POST["gift_wrap"] == "5"){$gift_wrap = 5; $giftyes = "yes";}else{$gift_wrap = 0; $giftyes = "no";}
$ordertotal = $_SESSION["tcost"] + $_SESSION["ship"] + $_SESSION["taxx"] + $express + $gift;
$_SESSION["mthis"] ="" ;
$_SESSION["mthis"] .=$row["fname"]." ".$row["lname"]."\n" ;
$_SESSION["mthis"] .=$row["addr"]."\n".$row["city"].", ".$row["stat"].", ".$row["zip"].", "."\n" ;
$_SESSION["mthis"] .=$row["country"]."\n".$row["email"]."\n".$row["phone"]."\n"."\n"."Order info:"."\n" ;
$sql="INSERT INTO orders(cust_id, cart_total, taxx, shipping, express, gift_wrap, s_first, s_last, s_addr, s_city, s_stat, s_zip, s_email, s_country, dt, s_phone) VALUES (".
"'".mysql_real_escape_string($row["id"])."', ".
"'".mysql_real_escape_string($ordertotal)."', ".
"'".mysql_real_escape_string($_SESSION["taxx"])."', ".
"'".mysql_real_escape_string($_SESSION["ship"])."', ".
"'".mysql_real_escape_string($expyes)."', ".
"'".mysql_real_escape_string($giftyes)."', ".
"'".mysql_real_escape_string($row["fname"])."', ".
"'".mysql_real_escape_string($row["lname"])."', ".
"'".mysql_real_escape_string($row["addr"])."', ".
"'".mysql_real_escape_string($row["city"])."', ".
"'".mysql_real_escape_string($row["stat"])."', ".
"'".mysql_real_escape_string($row["zip"])."', ".
"'".mysql_real_escape_string($row["email"])."', ".
"'".mysql_real_escape_string($row["country"])."',NOW(),'".mysql_real_escape_string($row["phone"])."') ";
$rs= mysql_query($sql,$o_conn) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
$oid = mysql_insert_id();
$result = mysql_query("select * from cart inner join items on cart.itemId = items.itemId where cart.cookieId = '" . mysql_real_escape_string( GetCartId() ) . "' order by items.itemName asc");
if (mysql_num_rows($result)==0){
echo mysql_num_rows($result);
}
while($row = mysql_fetch_array($result)){
$_SESSION["mthis"] .=$row["itemName"]."\n" ;
$_SESSION["mthis"] .="itemNumber: ".$row["itemNumber"]."\n" ;
$_SESSION["mthis"] .="Qty: ".$row["qty"]."\n" ;
$_SESSION["mthis"] .="gift_wrap: ".ucwords($row["gift_wrap"])."\n" ;
$_SESSION["mthis"] .="Unit Price: ".$row["price"]."\n"."\n" ;
$sql="INSERT INTO order_details(o_id, prod_id, name, itemNumber, qty, gift_wrap, unitprice, total) VALUES (".
"'".mysql_real_escape_string($oid)."', ".
"'".mysql_real_escape_string($row["itemId"])."', ".
"'".mysql_real_escape_string($row["itemName"])."', ".
"'".mysql_real_escape_string($row["itemNumber"])."', ".
"'".mysql_real_escape_string($row["qty"])."', ".
"'".mysql_real_escape_string($row["gift_wrap"])."', ".
"'".mysql_real_escape_string($row["price"])."', ".
"'".mysql_real_escape_string($row["price"]*$row["qty"])."') ";
$rs= mysql_query($sql, $o_conn) or die("<b>A fatal MySQL error occured</b>.\n<br />Query: " . $sql . "<br />\nError: (" . mysql_errno() . ") " . mysql_error());
}
$_SESSION["mthis"] .="Shipping = $ ".$_SESSION["ship"]."\n" ;
$_SESSION["mthis"] .="Express Shippig = $ ".$express."\n" ;
$_SESSION["mthis"] .="gift_wrap = $ ".$gift_wrap."\n" ;
if ($taxx != ""){$_SESSION["mthis"] .="Tax = $ ".$_SESSION["taxx"]."\n" ;}
$_SESSION["mthis"] .="Total = $ ".$ordertotal."\n" ;
$_SESSION["mthis"] .="........................................";
}else{
echo "error: $sql Failed";
}
}
?>