Guys, can someone help me out here, I am pretty stuck with some code I have written.
Having uploaded it to my web server I am having some problems, error message is:
Warning: Cannot add header information - headers already sent by (output started at /usr/home/aboutsuck/public_html/eshop/shop/checkout.php:2) in /usr/home/aboutsuck/public_html/eshop/shop/checkout.php on line 7
Code I am trying to run:
<?
//Set cookie, if not already set
if (!isset($user_id)){
$token = md5(uniqid(rand()));
setcookie("user_id", $token, time( )+86400, "/",".digital beatbox.com");
}
//create connection
$connection = mysql_connect("localhost", "username", "password") or die ("Sorry a connection to the server could not be established");
//select database
$db = mysql_select_db("aboutsuck", $connection) or die ("Sorry a connection to the database could not be established");
//Cart subtotal
$get_itemtot = "SELECT SUM(sel_item_totalprice) FROM TRACKING WHERE user_id = \"$user_id\"";
$itemtot_result = mysql_query($get_itemtot) or die ("Sorry we can't add up");
$itemtot = mysql_result($itemtot_result,0, "SUM(sel_item_totalprice)");
$fmt_itemtot = sprintf("%0.2f",$itemtot);
if ($itemtot <"50") {
$shipping = 4.5;
}
else {
$shipping = 0;
}
$fmt_shipping = sprintf("%0.2f",$shipping);
$total = $itemtot + $shipping;
$fmt_total =sprintf("%0.2f", $total);
//Get cart
$get_cart = "SELECT sel_item, sel_item_title, sel_item_qty, sel_item_price, sel_item_totalprice FROM TRACKING WHERE user_id = \"user_id\"";
$cart_result = mysql_query($get_cart) or die ("Couldn't get cart!");
$num_rows = mysql_numrows($cart_result);
if ($num_rows =="0"){
echo "You do not have anything in your cart, to checkout.";
} else {
echo "
<head>
</head>
<body>
<h1>Digital Beatbox : Checkout </h1>
<form method=post action=\"shop_sendorder.php\">
<h2>Billing Info</h2>
<table align=center width=700 border=0 cellpadding=0 cellspacing=0>
<tr>
<td><b>Full Name</b></td>
<td><input type=text name=\"fullname\">
</tr>
<tr>
<td><b>E-mail address</b></td>
<td><input type=text name=\"email\">
</tr>
<tr>
<td><b>Address Line 1</b></td>
<td><input type=text name=\"address1\">
</tr>
<tr>
<td><b>Address Line 2</b></td>
<td><input type=text name=\"address2\">
</tr>
<tr>
<td><b>Address Line 3</b></td>
<td><input type=text name=\"address3\">
</tr>
<td><b>Address Line 4</b></td>
<td><input type=text name=\"address4\">
</tr>
<tr>
<td><select name=\"cardtype\">
<option value=\"0\">--Select One--</option>
<option value=\"visa\">Visa</option>
<option value=\"mastercard\">Mastercard</option>
<option value=\"switch_solo\">Switch/Solo</option>
</select>
</td>
</tr>
<tr>
<td><b>Credit Card Number:</b></td>
<td><input type=text name=\"cc_num\" size=30>
</tr>
<tr>
<td><b>Credit Card Expiration Date</b></td>
<td><select name=\"cc_exp_mon\">
<option value=\"0\">--Select One--</option>
<option value=\"01\">01</option>
<option value=\"02\">02</option>
<option value=\"03\">03</option>
<option value=\"04\">04</option>
<option value=\"05\">05</option>
<option value=\"06\">06</option>
<option value=\"07\">07</option>
<option value=\"08\">08</option>
<option value=\"09\">09</option>
<option value=\"10\">10</option>
<option value=\"11\">11</option>
<option value=\"12\">12</option>
</select>
<select name=\"cc_exp_yr\">
<option value=\"0\">--Select One--</option>
<option value=\"2002\">2002</option>
<option value=\"2003\">2003</option>
<option value=\"2004\">2004</option>
<option value=\"2005\">2005</option>
<option value=\"2006\">2006</option>
<option value=\"2007\">2007</option>
<option value=\"2008\">2008</option>
<option value=\"2009\">2009</option>
<option value=\"2010\">2010</option>
</select>
</td>
</tr>
</table>
<h2>Cart Contents</h2>
<table align=center width=700 border=0 cellspacing=0 cellpadding=0>
<tr>
<td><b>Product_ID</b></td>
<td><b>Type</b></td>
<td><b>Title</b></td>
<td><b>Quantity</b></td>
<td><b>Price</b></td>
<td><b>Total</b></td>
</tr>
";
while ($row = mysql_fetch_array($cart_result)) {
//Get results and assign meaningful value
$sel_item = $row["sel_item"];
$sel_item_title = $row["sel_item_title"];
$sel_item_qty = $row["sel_item_qty"];
$sel_item_price = $row["sel_item_price"];
$sel_item_totalprice = $row["sel_item_totalprice"];
$fmt_item_totalprice = sprintf("0%.2f",$sel_item_totalprice);
echo"
<tr>
<td>$sel_item</td>
<td>$sel_item_title</td>
<td>$sel_item_qty</td>
<td>$sel_item_price</td>
<td>$sel_item_totalprice</td>
</tr>
";
}
echo "
<tr>
<td colspan=4 align=right><b>Item Total:</b></td>
<td><b>$ $fmt_itemtot</b></td>
</tr>
<tr>
<td colspan=4 align=right><b>Shipping:</b></td>
<td align=right>";
if ($shipping != "0"){
echo "<b>$ $fmt_shipping</b>";
} else {
echo "<b>Free</b>";
}
echo "
</td>
</tr>
<tr>
<td colspan=4 align=right><b>Total:</b></td>
<td align=right></b>$ $fmt_total</b></td>
</tr>
<tr>
<td colspan=4 align=center><input type=\"submit\" name=\"submit\" value=\"send this order\"></td>
</tr>
</table>
</form>
</body>
";
}
?>