Reputation: 5257
I've made a form. Currently this form does the following operations:
I'd like to change it to do the following operations:
Here is what I've done so far:
"form.php" contents
<html><head><title>Title</title></head><body>
<form action="php-form-processor.php" method="post">
<table border="0" cellspacing="5" width = "500">
<tr>
<td align="right" width="160">Choose an Item:</td>
<td align="left">
<select name="formItem" value="<?=$varItem;?>" class="input_full" >
<option value="1">Cheese</option>
</select>
</td>
</tr>
<tr bgcolor="#D0E8F5">
<td align="right" >Item count:</td>
<td align="left">
<input type="text" name="formItemCount" maxlength="50" value="<?=$varItemCount = 1;?>" class="input_full" />
</td>
</tr>
</table>
<p align="center">
<input type="submit" name="formSubmit" align = "center" value="Submit" />
</p>
</form></body></html>
"php-form-processor.php" contents
<?php
if($_POST['formSubmit'] == "Submit")
{
$varItem = $_POST['formItem'];
$varItemCount = $_POST['formItemCount'];
//database stuff
$username = "...";
$password = "...";
$hostname = "...";
// connect and add to the database varItem and varItemCount
mysql_query($sql);
mysql_close($dbhandle);
}
?>
The form is much bigger but i've simplified the stackoverflow's version of it. The price of an order must change according to "varItem" and "varItemCount" value. Basically I want to add "Pay with PayPal" option before writing an order into the database. P.S. I've already registered paypal Sandbox account and added "Buyer" and a "Seller".
what should I do next?
EDIT: ok, so here is a small guide how to solve the problem. Here are some advises:
Whole proccess looks like this:
$sql = "UPDATE paypal_test SET payed = '1' WHERE id = '".$_POST['custom']."'";
Now we have a database with completed and non-completed forms. Additionaly you can write a logic which will remove "old" uncompleted orders. For this reason you can create additional column called "date" and then compare: if (current_date.days - old_date.days > 7) -> remove from DB. That's it!
Upvotes: 6
Views: 5276
Reputation: 75
Tat late to the party....but in 2021 try this..
If you want to use a custom form in combination with paypals Smart Payment Buttons (https://developer.paypal.com/docs/checkout/) then you could try this approach. That works for me and you also don't need IPN (below approach is most current and much faster).
On your frontend use this (w/ this you can send your form data to your server):
https://developer.paypal.com/demo/checkout/#/pattern/server
On you backend use this (I put create & capture code in one file):
To create the order:
https://developer.paypal.com/docs/checkout/reference/server-integration/set-up-transaction/
To capture the order:
https://developer.paypal.com/docs/checkout/reference/server-integration/capture-transaction/
To set it up:
https://developer.paypal.com/docs/checkout/reference/server-integration/setup-sdk/
Now you can write form data to your db after paypal approved the order.
Gave similar answer here
How to submit data for the address and payment details after PayPal payment is made
Upvotes: 0
Reputation: 805
I would not accept what the PayPal post back is giving you, it's a sloppy way of checking the authentication of the user and expects the user to click the "go back to website" button. Instead use the IPN (https://www.paypal.com/ipn/) and make sure you post the response back to PayPal for verification.
Checkout this PHP example from PayPal: https://cms.paypal.com/uk/cgi-bin/?cmd=_render-content&content_ID=developer/e_howto_admin_IPNImplementation
Upvotes: 1
Reputation: 8030
Well, you pretty much already described what you need to do:
PS: I hope you are not waiting for someone to actually rewrite the whole script for you ;)
Upvotes: 2