Okay, took a break thinking that was my problem. I was totally fried. Well, it's still not working. I'm still not sure what I'm doing wrong. I'm sure it's one of those "DUH" things, but I'm not seeing it.
It works fine if the Paypal form information is outside of the PHP code, but then it messes it up and doesn't properly submit the items. Either it was supposed to be one and it submitted two (because I had two slots). Or I have three items and it only submits two...:eek: So I figure it needs to be in PHP (which makes more sense, but I'm still learning), but then it submits nothing to the PayPal site.
Here is my code.
<?php
// Connect
require_once ("/config.inc");
$display_block = "<h1>Nascar Drivers - Shopping Cart</h1>";
//check for cart items
$get_cart_sql = "SELECT sc.sp_num, p.product_num, p.product_name, p.product_price, sc.sel_item_qty
FROM shopping_cart AS sc
LEFT JOIN product AS p
ON p.product_num = sc.sel_item_id
WHERE session_id = '".$_COOKIE["PHPSESSID"]."'";
$get_cart_res = mysql_query($get_cart_sql, $db_connection) or die(mysql_error());
if (mysql_num_rows($get_cart_res) < 1 ) {
$display_block = "
<table cellpadding=\"3\" cellspacing=\"2\" border=\"0\" width=\"100%\">
<tr><br /><p align=\"left\">You have no items in your cart.
Please <a style=\"text-decoration: none\" href=\"http://gregsgoods.com\">continue to shop</a>!</p></tr></table>";
} else {
$display_block .= "<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">
<table cellpadding=\"3\" cellspacing=\"2\" border=\"0\" width=\"100%\">
<tr>
<th align=\"right\">Product ID</th>
<th align=\"left\">Product</th>
<th align=\"right\">Qty</th>
<th align=\"right\">Price</th>
<th align=\"right\">Total Price</th>
<th align=\"center\">Action</th>
</tr>";
$total_cart=0;
setlocale(LC_MONETARY, 'en_US');
while ($cart_info = mysql_fetch_array($get_cart_res)) {
$id = $cart_info['sp_num'];
$product_num = $cart_info['product_num'];
$product_name = stripslashes($cart_info['product_name']);
$product_price = $cart_info['product_price'];
$product_qty = $cart_info['sel_item_qty'];
$total_price = sprintf('%.2f', $product_price * $product_qty);
$display_block .= "
<tr>
<td align=\"right\">$product_num <br /></td>
<td align=\"left\">$product_name <br /></td>
<td align=\"right\">$product_qty <br /></td>
<td align=\"right\">$" .$product_price. "<br /></td>
<td align=\"right\">$" .$total_price. "<br /></td>
<td align=\"center\"><a style=\"text-decoration: none\" href=\"removefromcart.php?id=".$id."\">Remove</a></td>
</tr>
<input type=\"hidden\" name=\"item_name\"
value=\"<?php echo $product_name ?>\">
<input type=\"hidden\" name=\"amount\" value=\"<?php echo $product_name ?>\">";
$total_cart += $total_price;
} //END WHILE
switch(TRUE){
case (0 <= $total_cart && $total_cart < 25):
$shipping_total = 5.95;
break;
case (25.01 <= $total_cart && $total_cart < 50):
$shipping_total = 7.95;
break;
case (50.01 <= $total_cart && $total_cart < 75):
$shipping_total = 10.95;
break;
case (75.01 <= $total_cart && $total_cart < 100):
$shipping_total = 14.95;
break;
case (100.01 <= $total_cart && $total_cart < 9000):
$shipping_total = 0;
break;
}
$shipping_cost = $shipping_total;
$display_block .= "
<tr>
<td> </td>
<td> </td>
<td> </td>
<td>Shipping Total:</td>
<td align=\"right\">$" . sprintf('%01.2f', $shipping_cost) . "</td>
<td> </td></tr>";
$total_amount = $total_cart+$shipping_cost;
$display_block .= "
<tr>
<td> </td>
<td> </td>
<td> </td>
<td>Grand Total:</td>
<td align=\"right\">$" . sprintf('%01.2f', $total_amount) . "</td>
<td> </td></tr></table>";
$display_block .= "<p>Would you like to <a href=\"http://gregsgoods.com/\">continue to shop</a>?</p>
<input type=\"hidden\" name=\"cmd\" value=\"_cart\">
<input type=\"hidden\" name=\"upload\" value=\"1\">
<input type=\"hidden\" name=\"business\"
value=\"greg@gregsgoods.com\">
<input type=\"submit\" value=\"PayPal\">
</form>";
}
echo $display_block;
?>