Reputation: 97
I've set up a site where customers enter their information (name, address, etc.) and want them to be able to pay using a credit card via paypal. That works well. I've set up Paypal instant payment notification and set it up through paypal that the customer gets redirected to my page. It all works properly except that the data isn't being passed along and saved to my SQL database. I know that the code that inserts the data into the database works properly. The problem is that the data isn't being passed to that page since the paypal pages are in between.
Here is the php I have
if (isset($_POST['child_name'])
&& isset($_POST['age'])
&& isset($_POST['hometown'])
&& isset($_POST['boy_girl'])
&& isset($_POST['email'])
&& isset($_POST['first_name'])
&& isset($_POST['last_name'])
&& isset($_POST['address1'])
&& isset($_POST['address2'])
&& isset($_POST['city'])
&& isset($_POST['state'])
&& isset($_POST['zip'])
&& isset($_POST['country'])) {
$child_name = $_POST['child_name'];
$age = $_POST['age'];
$hometown = $_POST['hometown'];
$boy_girl = $_POST['boy_girl'];
$email = $_POST['email'];
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$city = $_POST['city'];
$state = $_POST['state'];
$zip = $_POST['zip'];
$country = $_POST['country'];
}
And here is the HTML
<form action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick">
<input type="hidden" name="hosted_button_id" value="NT2YC6LP7SWBE">
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_paynowCC_LG.gif" border="0" name="submit" alt="PayPal - The safer, easier way to pay online!">
<input type="hidden" name="child_name" id="child_name" value ="<? echo $child_name; ?>" maxlength="20"/>
<input type="hidden" name="age" id="age" value ="<? echo $age; ?>" maxlength="4"/>
<input type="hidden" name="hometown" id="hometown" value ="<? echo $hometown; ?>" maxlength="32"/>
<input type="hidden" name="boy_girl" id="boy_girl" value ="<? echo $boy_girl; ?>" maxlength="4"/>
<input type="hidden" name="first_name" id="first_name" value ="<? echo $first_name; ?>" maxlength="32"/>
<input type="hidden" name="last_name" id="last_name" value ="<? echo $last_name; ?>" maxlength="32"/>
<input type="hidden" name="email" id="email" value ="<? echo $email; ?>" maxlength="64"/>
<input type="hidden" name="address1" id="address1" value ="<? echo $address1; ?>" maxlength="64"/>
<input type="hidden" name="address2" id="address2" value ="<? echo $address2; ?>" maxlength="32"/>
<input type="hidden" name="city" id="city" value ="<? echo $city; ?>" maxlength="32"/>
<input type="hidden" name="state" id="state" value ="<? echo $state; ?>" maxlength="20"/>
<input type="hidden" name="zip" id="zip" value ="<? echo $zip; ?>" maxlength="10"/>
<input type="hidden" name="country" id="country" value ="<? echo $country; ?>" maxlength="32"/>
<input type="hidden" name="payment_type" id="payment_type" value ="paypal" maxlength="6"/>
<input type="hidden" name="paid" id="paid" value ="yes" maxlength="3"/>
<input type="hidden" name="mailed" id="mailed" value ="no" maxlength="3"/>
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1">
</form>
I just took the form that paypal gave me and added the hidden inputs. This works perfectly on another page but that is because the action attribute leads directly to the page that will insert the data. Here the action sends them to paypal's site and the data never makes it to mine. How do I adjust this?
Upvotes: 1
Views: 481
Reputation: 8528
You can't do this because of the flow. Two solutions:
Try to store all of the information in Paypal's custom
field (255 chars) using a separator character
Store the custom information in the DB with a unique key and store the unique key in the custom
field so you can retrieve it later with the IPN response
You should not be doing anything DB related until you get an IPN response, that is the point of IPN. What you are describing here is PDT which relies on the customer to return to your page after the payment process which doesn't ALWAYS happen.
Upvotes: 1
Reputation: 10327
As kalpaitch suggested, you should save your data into session and pull it back when the visitor returns from the paypal pages.
Upvotes: 0