Okay, I've searched and searched...I'm not finding the answer to my problem here. I'm trying to get the shopping cart to load to PayPal. It keeps telling me the shopping cart is empty, but on the site...it has stuff in it.

Anywho...I think my form information might be in the wrong place, but I can't seem to find the right place it should be.

I'm not sure if anyone will need more code. Here is the code that I think is the problem:


// Connect
require_once ("/config.inc");
$display_block = "<h1>Nascar Drivers - Shopping Cart</h1>
<form action=\"https://www.paypal.com/cgi-bin/webscr\" method=\"post\">";

//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=\"seestore.php\">continue to shop</a>!</p></tr></table>";
} else {
	$display_block .= "
	<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>";
	$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>&nbsp</td>
<td>&nbsp</td>
<td>&nbsp</td>
<td>Shipping Total:</td>
<td align=\"right\">$" . sprintf('%01.2f', $shipping_cost) . "</td>
<td>&nbsp</td></tr>";

$total_amount = $total_cart+$shipping_cost; 


$display_block .= "
<tr>
<td>&nbsp</td>
<td>&nbsp</td>
<td>&nbsp</td>
<td>Grand Total:</td>
<td align=\"right\">$" . sprintf('%01.2f', $total_amount) . "</td>
<td>&nbsp</td></tr></table>";

$display_block .= "<p>Would you like to <a href=\"seestore.php\">continue to shop</a>?</p>";

$display_block .= "<table>
   <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=\"hidden\" name=\"product_name\"
      value=\"".$_GET["product_name"]."\"/>
   <input type=\"hidden\" name=\"product_price\" value=\"".$_GET["product_price"]."\"/>
   <input type=\"submit\" value=\"Pay with PayPal\"/>
   </form></table>";
}
echo $display_block;

    Ignore that, i was blind, please provide the url of the cart in action and i will take a look, i have written have a dozen shoping carts using papal for clients.

      okay, I think I understand (which might be why I couldn't find the exact answer I was looking for)...I have to add to paypal's cart for each item? not my cart? and then it works?

        no you don't you can build the order on your site then pass the aggregated cart to paypal, but you can do it per item if you wish

          if you view the source if your page you will see:

          <input type="hidden" name="product_name"
          value=""/>
          <input type="hidden" name="product_price" value=""/>

          obviously a problem

            okay, so what am I missing? I tried to following this link, but...I'm not sure what I'm missing. Maybe I'm thinking too hard.

              you want $total_amount not

              $_GET["product_price"]

              or you need item_name_1,amount_1 for individualised items

                okay, I see way up there you asked for the url. This is the site I'm working on: http://gregsgoods.com/. Does that help?

                I'll try to work on more of what you just said as well. But for now I added in just the information from paypal for uploading the cart...but not with the right information...(I feel like I'm so not making sense).

                  well i just tested, apart from putting in the right item name and amounts it works

                    okay, I'm closer. I see what I didn't do. I had to echo the prices. However, now, do I need to do a while loop in case they purchase more than one item? I notice that if I have it like the below and only one item it prints the item twice. Or if I have more than two items...they don't show up.

                    Do I do this code in my PHP while loop? I'll practice sometime today.

                    <form action="https://www.paypal.com/cgi-bin/webscr" method="post">
                       <input type="hidden" name="cmd" value="_cart">
                       <input type="hidden" name="upload" value="1">
                       <input type="hidden" name="business"
                          value="rebecca@gregsgoods.com">
                       <input type="hidden" name="item_name_1"
                          value="<?php echo $product_name ?>">
                       <input type="hidden" name="amount_1" value="<?php echo $product_price ?>">
                       <input type="hidden" name="item_name_2"
                          value="<?php echo $product_name ?>">
                       <input type="hidden" name="amount_2" value="<?php echo $product_price ?>">
                       <input type="submit" value="PayPal">
                    </form>

                    BTW, thanks so much for your help!! I really, really appreciate it. 🙂

                      I think I'm brain dead. :glare:

                      Anywho...I know that whatever the answer is to this person's post...is what I need. But he didn't post the answer.

                      I'm trying various versions of this, but not getting it to work.

                        you already have the loop for displaying the items to the client, you just need to add a bit for the form to be sent to paypal.

                          I just went through something similar trying to integrate my shopping cart into the PayPal checkout.

                          I'm not sure if you're trying to use the PayPal Express Checkout, but here's the sample code they provide:
                          https://www.paypal.com/IntegrationCenter/ic_nvp.html

                          Scroll down and get the PHP zip file. Open up the index.html page and start clicking around, also read the readme.html page. From what I gather, most of the pages are Admin pages so there's really only the Express Checkout and Credit Card Direct Payment pages that are shown to the user.

                          Good luck.

                            6 days later

                            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>&nbsp</td> <td>&nbsp</td> <td>&nbsp</td> <td>Shipping Total:</td> <td align=\"right\">$" . sprintf('%01.2f', $shipping_cost) . "</td> <td>&nbsp</td></tr>"; $total_amount = $total_cart+$shipping_cost; $display_block .= " <tr> <td>&nbsp</td> <td>&nbsp</td> <td>&nbsp</td> <td>Grand Total:</td> <td align=\"right\">$" . sprintf('%01.2f', $total_amount) . "</td> <td>&nbsp</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; ?>

                              <input type=\"hidden\" name=\"item_name\"
                              value=\"<?php echo $product_name ?>\">

                              should just be

                              <input type=\"hidden\" name=\"item_name\"
                              value=\" ".$product_name". \">

                                well, I changed it...it's still not relaying info to PayPal. I still get "Cart is Empty". 🙁

                                  item_name_x
                                  amount_x

                                  starting at 1

                                    you probably hate me by now, but your help has been great!

                                    I created a for loop, but it is only pulling one item as well. But at least I'm not getting "cart empty". Here is the code:

                                    <?php
                                    for($i=0; $i < count($get_cart_res); $i++){ 
                                    $val = $i + 1; 
                                    $display_block .= "<input type=\"hidden\" name=\"item_name_$val\"
                                         value=\" ".$product_name." \">";
                                    $display_block .= "<input type=\"hidden\" name=\"amount_$val\" value=\"".$product_price." \">";
                                    }
                                    ?>
                                    

                                      you can use the while loop you already have to display each item you don't need the for loop, just he counter idea ($i)

                                            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);
                                         $i=1;
                                            $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_$i\"
                                              value=\"".$product_name."\">
                                        <input type=\"hidden\" name=\"amount_$i\" value=\"".$product_name."\">";
                                                $total_cart += $total_price;  
                                        $i++; } //END WHILE