Lassie Posted April 18, 2007 Share Posted April 18, 2007 I am trying to link my cart to paypal. I have successffully done this passing the total value of the cart. I now want to pass the individual line items and prices. These are required to be passsed as form variables. These are in the form of item_name_1 amount_1 item_name_2 amount_2 etc for all the items in the cart. For this I have the following function. function display_pp_form($name,$email, $Cheque = true) { ?> <table border = 0 width = '700' cellspacing = 0 align = center> <tr><th colspan = 2 bgcolor="#cccccc">Thank you <?php echo "$name";?></br>"If you wish to pay by CREDIT CARD please click on the the PayPal logo and you will be transferred to a secure processing center.</br> If you wish to pay by CHEQUE, please choose the cheque button.</br> </th></tr> <tr><td> <form action="https://www.sandbox.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="tina@hawkesleypublishing.com"> <?php $fld_idx = 1; foreach ($cart as $product_id => $qty) { $book = get_book_details($product_id); echo '<input type="hidden" name="item_name_' . $fld_idx . '" value="' . $book["title"] . '">'; echo '<input type="hidden" name="amount_' . $fld_idx . '" value="' . $book["price"] . '">'; $fld_idx++; } ?> <input type="hidden" name="currency_code" value="GBP"> <input type="hidden" name="amount" value="<?php echo $_SESSION['total_price'] ?>"> <input type="hidden" name="custom" value="<?php echo $name ?>"> //<input type="hidden" name="email" value="<?php echo $email ?>"> <input type="image" src="images/paypal.gif" name="submit" alt="Make payments with PayPal - it's fast, free and secure!" align="center"> </form> The problem is that I get an invalid argument error and no values are passed to the paypal site. Warning: Invalid argument supplied for foreach() in c:\easyserv\www\e_cart12\display_fns.php on line 500 How can I debug the form? Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted April 18, 2007 Share Posted April 18, 2007 Where is the variable "$cart" defined? It's not being passed to the function. Ken Quote Link to comment Share on other sites More sharing options...
Glyde Posted April 18, 2007 Share Posted April 18, 2007 Add: global $cart; To the top of your function. It should solve the problem, if not...then $cart hasn't been defined or was defined within another function, instead of globally. Quote Link to comment Share on other sites More sharing options...
Lassie Posted April 18, 2007 Author Share Posted April 18, 2007 Thanks guys,that solved it. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.