I'm actually stuck, sending a form post request to multiple action receiver.
What am I trying to do?
I'm trying to send an post request to my database and to paypal at the same time using one button.
After the user submitted the form, I want my PHP script to post those informations to the database before redirecting to paypal. To work with those sent informations.
My actual code:
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="item_name" id="item_name" value="Helpful.ninja coins"/>
<input type="hidden" name="business" value="pr0bpayment@gmail.com">
<input type="hidden" name="return" value="http://helpful.ninja/?username=payment_complete=1">
<input type="hidden" name="image_url" value="http://helpful.ninja/assets/images/logo_dark.png">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="amount" class="amountToPay" value="">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="bn" value="PP-BuyNowBF">
<button type="submit" name="submit" alt="PayPal - The safer, easier way to pay online!" class="btn bg-danger-400">Purchase now <i class="icon-paypal position-right"></i></button>
</form>
<?php
require_once('../handling/database.php');
require_once('../handling/user.class.php');
require_once('../handling/purchase.class.php');
require_once('../handling/config.php');
$user = new user($_SESSION['Username']);
$config = new config();
if(!empty($_POST)){
$purchase = new purchase($user->username, $user->coins, $_POST['coinValue'], $config->coin_price);
$purchase->insert_purchase($user->username, $user->email, $_SERVER['REMOTE_ADDR'], $purchase->ordernumber, $purchase->purchase_amount, $purchase->price);
}
?>
<script type="text/javascript">
$(".coinValue").bind("change paste keyup", function() {
$(".amountToPay").val($(this).val() * <?php echo $config->coin_price; ?>);
});
</script>
So I'm trying to post the following code:
if(!empty($_POST)){
$purchase = new purchase($user->username, $user->coins, $_POST['coinValue'], $config->coin_price);
$purchase->insert_purchase($user->username, $user->email, $_SERVER['REMOTE_ADDR'], $purchase->ordernumber, $purchase->purchase_amount, $purchase->price);
}
to the databse before the user gets redirected to paypal.
Does anyone have an idea how to manage this?