I have a catalogue that I have designed and I am trying to use PayPal's shopping cart. PayPal offers limited pulldown selections, but I have managed to get through that episode. The problem is, after a user selects certain aspects of an item, php queries the database for the price of that specific item depending on the size, color, etc. that was selected. After that the PayPal specific information needs to be submitted in their format.
The only way I was able to get this to work is to post the data from the query to another page then auto submit it to PayPal. This works ok, until the user selects the "continue shopping" option on PayPal which then sends them right back to secondary form page.
If I try to integrate the PayPal data form in with the item aspects selection form, it will not work. I'm assuming the posted data is not recognized by the PayPal shopping cart and it goes directly to the PayPal login page instead of the shopping cart.
What I need to do is allow a user to select certain aspects of the product (size, color, material, etc.). Then when they click "Add to cart", it queries the database for the price using the selected data, then only posts certain information to PayPal. I'm not quite sure how to do this using just one form and submit.
<form id="form2" name="form2" target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<select size="1" name="color" id="color">
<option value="white-linen">White Linen</option>
<option value="cream-linen">Cream Linen</option>
<option value="khaki-linen">Khaki Linen</option>
</select>
<select size="1" name="material" id="material">
<option value="Linen/Silk">Linen/Silk</option>
<option value="Cotton">Cotton</option>
</select>
<select size="1" name="size" id="size">
<option value="King">King</option>
<option value="Queen">Queen</option>
<option value="Full">Full</option>
<option value="Twin">Twin</option>
</select>
<input type="image" src="https://www.paypal.com/en_US/i/btn/btn_cart_SM.gif" border="0" name="submit" id="submit" alt="PayPal - The safer, easier way to pay online!">
<?php
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
if(isset($_POST['submit']))
{
$product = "All In One Duvet";
$color = $_POST['color'];
$material = $_POST['material'];
$size = $_POST['size'];
$query = "SELECT price FROM catalogue WHERE product='$product' AND material='$material' AND size='$size'";
$result = mysql_query($query) or die('Error, select query failed');
list($price) = mysql_fetch_array($result);
?>
<input type="hidden" name="on0" value="Color">
<input type="hidden" name="os0" value="<?php echo $color?>">
<input type="hidden" name="on1" value="Material">
<input type="hidden" name="os1" value="<?php $material?>">
<input type="hidden" name="on2" value="Size">
<input type="hidden" name="os2" value="<?php echo $size?>">
<input type="hidden" name="bn" value="PP-ShopCartBF">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="no_shipping" value="2">
<input type="hidden" name="amount" value="<?php echo $price?>">
<input type="hidden" name="item_name" value="All In One Duvet">
<input type="hidden" name="business" value="email@address.com">
<input type="hidden" name="cmd" value="_cart">
<input type="hidden" name="add" value="1">
<?php
}
?>
</form>