As you will see, I’m new to coding so be gentle ….
I have a MySQL database which has products and I have populated a dropdown that displays the products and price (concatenate the 2 $item & $price), this (apparently is working). What I can’t figure out is how in the heck do I pass the chosen dropdown value to a form (PayPal), currently its always passing the last value in the dropdown.
Database is like this:
Item price
Product1 | 12.00
Product2 | 13.00
Product3 | 14.00
Product4 | 15.00
Product5 | 16.00
Etc …
Dropdown has all the above values but when choose any value and click submit, Product5 is sent to the PayPal form, basically the last one every time.
Here’s the code:
<?php
include('../../../config.php');
if (!$db_con)
{
die('Could not connect: ' . mysql_error());
}
function options(){
global $OPTION;
$result = mysql_query("SELECT * FROM products");
if (!$result)echo "Error in query";
else {
$count=mysql_num_rows($result);
if ($count==0) echo "Nothing found";
else {
for ($i=0; $i<$count; $i++){
$OPTION=mysql_result($result, $i, 'title');
$VALUE=mysql_result($result, $i, 'price');
echo "<OPTION VALUE=$value>$OPTION $ $VALUE</option>"; // Builds the Dropdown
}
}
}
}
echo "<select name='select'>";
options();
echo "</select>";
?>
<form method="post" action="https://www.paypal.com/cgi-bin/webscr" target="post">
<input type="hidden" name="cmd" value="_cart" />
<input type="hidden" name="business" value="address@email.com" />
<input type="hidden" name="amount" value="1.00">
<input type="hidden" name="item_name" value="<?php echo $_POST['$OPTION']; ?>"> // This displays the last record no matter what user chooses
<input type="hidden" name="item_number" value="item_number" />
<input type="hidden" name="return" value="http://www.DOMAIN.com/thankyou" />
<input type="hidden" name="currency_code" value="USD" />
<input type="hidden" name="undefined_quantity" value="1" />
<input type="hidden" name="no_note" value="1" />
<input type="hidden" name="bn" value="PP-BuyNowBF" />
<input type="hidden" name="add" value="1" />
<input type="submit" value="Add To Cart" />
</form>