14 FEB

How to Set Up PayPal Integration with PHP & MySQL

This post was last updated on Tuesday 15th September 2015

PayPal is the most popular payment service on the web so being able to integrate your website with PayPal’s Instant Payment Notification Service (IPN) is essential if you need to process payments through your website.

There are 3 main parts to the PayPal IPN system.

  1. A webpage that initiates a request to PayPal to make a payment.
  2. A PHP page on your webserver that PayPal calls to notify you that payment has been made.
  3. A webpage that confirms the above payment and continues on to the next phase of your web application, such as a ‘Thank You’ page.

Parts 1 and 3 are accessible by customers on your website. Part 2 is only visible to PayPal.  The diagram below illustrates the interaction between your customer, PayPal and your website.

PayPal Interaction

The following steps break down each part of the process into easy to follow chunks, it is assumed that you have knowledge of PHP and MySQL.


  • If you are not receiving the correct response from Paypal ensure that you are using the main test account (Verified Business Account) from your Paypal Sandbox account.
  • Also ensure that you are testing the Paypal IPN Script on an online webserver (Not MAMP, Xampp etc..) as Paypal requires a reachable ‘return url’, ‘cancel url’ and ‘notify url’.

Step 1 – Setup PayPal Account

Sign up for a PayPal account if you don’t already have one. In order to use IPN, the Paypal account you are selling from must be a Business Account.

Once you have a registered PayPal account your account must be setup correctly to use IPN.

Select ‘edit profile’ from your PayPal account and check the following settings.

  • Under ‘My Selling Preferences’ >> ‘Getting paid and managing risk’ >> ‘Instant Payment Notification Preferences’
    • Set the IPN value to ‘On’
    • Set the IPN URL to the PHP page containing the IPN code shown in steps 3 & 4 of this tutorial. (http://www.example.com/payment.php)
  • Under ‘My Selling Preferences’ >> ‘Getting paid and managing risk’ >> ‘Block payments’
    • Block payments from users who pay with eCheque. (This is because these will not be instant payments)
  • Under ‘account information’ >> ’email’
    • Note down your primary email address. This email will be visible to users so make it a professional one. User’s may feel apprehensive about sending money to an e-mail address with the domain ‘hotmail.com’ or ‘Yahoo.com’ etc…

Step 2 – Simple HTML Form

Your website must now send all the required values to PayPal so that the payment can be processed.

The following code example demonstrates a basic form that we will use to send the values:

<!DOCTYPE html>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title>Paypal Integration Test</title>

<form class="paypal" action="payments.php" method="post" id="paypal_form" target="_blank">
		<input type="hidden" name="cmd" value="_xclick" />
		<input type="hidden" name="no_note" value="1" />
		<input type="hidden" name="lc" value="UK" />
		<input type="hidden" name="currency_code" value="GBP" />
		<input type="hidden" name="bn" value="PP-BuyNowBF:btn_buynow_LG.gif:NonHostedGuest" />
		<input type="hidden" name="first_name" value="Customer's First Name" />
		<input type="hidden" name="last_name" value="Customer's Last Name" />
		<input type="hidden" name="payer_email" value="customer@example.com" />
		<input type="hidden" name="item_number" value="123456" / >
		<input type="submit" name="submit" value="Submit Payment"/>


The business name, price, submit type, notify URL and other sensitive values will be sent during the next step.

A full list of the values to send can be found at the PayPal website under the title “A Sample IPN Message and Response”.

Step 3 – Payments.php (The Request)

The payment.php page will be used to handle the outgoing request to PayPal and also to handle the incoming response after the payment has been processed.

The following sample code shows the querystring being constructed before it is posted to PayPal. Here you can specify the following values:

  • Business ($paypal_email) – Enter the email address of your PayPal account.
  • Item name ($item_name) – The name of the item being purchased.
  • Amount ($item_amount) – The price of the item.
  • Return ($return_url) – The address to return to after a successful payment.
  • Cancel Return ($cancel_url) – the address to return to after a cancelled payment.
  • Notify URL ($notify_url) – The address of the payments.php page on your website.
  • Custom – Any other data to be sent and returned with the PayPal request.
// Database variables
$host = "localhost"; //database location
$user = ""; //database username
$pass = ""; //database password
$db_name = ""; //database name

// PayPal settings
$paypal_email = 'user@domain.com';
$return_url = 'http://domain.com/payment-successful.html';
$cancel_url = 'http://domain.com/payment-cancelled.html';
$notify_url = 'http://domain.com/payments.php';

$item_name = 'Test Item';
$item_amount = 5.00;

// Include Functions

// Check if paypal request or response
if (!isset($_POST["txn_id"]) &amp;amp;amp;amp;amp;amp;&amp;amp;amp;amp;amp;amp; !isset($_POST["txn_type"])){
    $querystring = '';
    // Firstly Append paypal account to querystring
    $querystring .= "?business=".urlencode($paypal_email)."&amp;amp;amp;amp;amp;amp;";
    // Append amount&amp;amp;amp;amp;amp;amp; currency (£) to quersytring so it cannot be edited in html
    //The item name and amount can be brought in dynamically by querying the $_POST['item_number'] variable.
    $querystring .= "item_name=".urlencode($item_name)."&amp;amp;amp;amp;amp;amp;";
    $querystring .= "amount=".urlencode($item_amount)."&amp;amp;amp;amp;amp;amp;";
    //loop for posted values and append to querystring
    foreach($_POST as $key =&amp;amp;amp;amp;amp;gt; $value) {
        $value = urlencode(stripslashes($value));
        $querystring .= "$key=$value&amp;amp;amp;amp;amp;amp;";
    // Append paypal return addresses
    $querystring .= "return=".urlencode(stripslashes($return_url))."&amp;amp;amp;amp;amp;amp;";
    $querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&amp;amp;amp;amp;amp;amp;";
    $querystring .= "notify_url=".urlencode($notify_url);
    // Append querystring with custom field
    //$querystring .= "&amp;amp;amp;amp;amp;amp;custom=".USERID;
    // Redirect to paypal IPN
} else {
   // Response from PayPal

Step 4 – Payments.php (The Response)

The next part of the payments.php page handles the response from PayPal. The response is re-assigned to variables and then posted back to PayPal for verification using fsockopen.

If the response is VERIFIED then a validation check can be performed. The check_txnid and check_price functions are called to check that the correct Transaction ID and Price have been returned. The updatePayments function can finally be called to store the details of the payment in the payments table (Step 6).

// Database variables
$host = "localhost"; //database location
$user = ""; //database username
$pass = ""; //database password
$db_name = ""; //database name

// PayPal settings
$paypal_email = 'user@domain.com';
$return_url = 'http://domain.com/payment-successful.html';
$cancel_url = 'http://domain.com/payment-cancelled.html';
$notify_url = 'http://domain.com/payments.php';

$item_name = 'Test Item';
$item_amount = 5.00;

// Include Functions

// Check if paypal request or response
if (!isset($_POST["txn_id"]) &amp;amp;amp;&amp;amp;amp; !isset($_POST["txn_type"])){
    $querystring = '';
    // Firstly Append paypal account to querystring
    $querystring .= "?business=".urlencode($paypal_email)."&amp;amp;amp;";
    // Append amount&amp;amp;amp; currency (£) to quersytring so it cannot be edited in html
    //The item name and amount can be brought in dynamically by querying the $_POST['item_number'] variable.
    $querystring .= "item_name=".urlencode($item_name)."&amp;amp;amp;";
    $querystring .= "amount=".urlencode($item_amount)."&amp;amp;amp;";
    //loop for posted values and append to querystring
    foreach($_POST as $key =&amp;amp;gt; $value){
        $value = urlencode(stripslashes($value));
        $querystring .= "$key=$value&amp;amp;amp;";
    // Append paypal return addresses
    $querystring .= "return=".urlencode(stripslashes($return_url))."&amp;amp;amp;";
    $querystring .= "cancel_return=".urlencode(stripslashes($cancel_url))."&amp;amp;amp;";
    $querystring .= "notify_url=".urlencode($notify_url);
    // Append querystring with custom field
    //$querystring .= "&amp;amp;amp;custom=".USERID;
    // Redirect to paypal IPN
} else {
    //Database Connection
    $link = mysql_connect($host, $user, $pass);
    // Response from Paypal

    // read the post from PayPal system and add 'cmd'
    $req = 'cmd=_notify-validate';
    foreach ($_POST as $key =&amp;amp;gt; $value) {
        $value = urlencode(stripslashes($value));
        $value = preg_replace('/(.*[^%^0^D])(%0A)(.*)/i','${1}%0D%0A${3}',$value);// IPN fix
        $req .= "&amp;amp;amp;$key=$value";
    // assign posted variables to local variables
    $data['item_name']          = $_POST['item_name'];
    $data['item_number']        = $_POST['item_number'];
    $data['payment_status']     = $_POST['payment_status'];
    $data['payment_amount']     = $_POST['mc_gross'];
    $data['payment_currency']   = $_POST['mc_currency'];
    $data['txn_id']             = $_POST['txn_id'];
    $data['receiver_email']     = $_POST['receiver_email'];
    $data['payer_email']        = $_POST['payer_email'];
    $data['custom']             = $_POST['custom'];
    // post back to PayPal system to validate
    $header = "POST /cgi-bin/webscr HTTP/1.0\r\n";
    $header .= "Content-Type: application/x-www-form-urlencoded\r\n";
    $header .= "Content-Length: " . strlen($req) . "\r\n\r\n";
    $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);
    if (!$fp) {
        // HTTP ERROR
    } else {
        fputs($fp, $header . $req);
        while (!feof($fp)) {
            $res = fgets ($fp, 1024);
            if (strcmp($res, "VERIFIED") == 0) {
                // Used for debugging
                // mail('user@domain.com', 'PAYPAL POST - VERIFIED RESPONSE', print_r($post, true));
                // Validate payment (Check unique txnid &amp;amp;amp; correct price)
                $valid_txnid = check_txnid($data['txn_id']);
                $valid_price = check_price($data['payment_amount'], $data['item_number']);
                // PAYMENT VALIDATED &amp;amp;amp; VERIFIED!
                if ($valid_txnid &amp;amp;amp;&amp;amp;amp; $valid_price) {
                    $orderid = updatePayments($data);
                    if ($orderid) {
                        // Payment has been made &amp;amp;amp; successfully inserted into the Database
                    } else {
                        // Error inserting into DB
                        // E-mail admin or alert user
                        // mail('user@domain.com', 'PAYPAL POST - INSERT INTO DB WENT WRONG', print_r($data, true));
                } else {
                    // Payment made but data has been changed
                    // E-mail admin or alert user
            } else if (strcmp ($res, "INVALID") == 0) {
                // PAYMENT INVALID &amp;amp;amp; INVESTIGATE MANUALY!
                // E-mail admin or alert user
                // Used for debugging
                //@mail("user@domain.com", "PAYPAL DEBUGGING", "Invalid Response
data =
&amp;amp;lt;pre&amp;amp;gt;".print_r($post, true)."&amp;amp;lt;/pre&amp;amp;gt;

    fclose ($fp);

Step 5 – Functions.php

The payments.php page calls upon a number of functions used to validate the returned data and store the response in the database.

// functions.php
function check_txnid($tnxid){
	global $link;
	return true;
	$valid_txnid = true;
	//get result set
	$sql = mysql_query("SELECT * FROM `payments` WHERE txnid = '$tnxid'", $link);
	if ($row = mysql_fetch_array($sql)) {
		$valid_txnid = false;
	return $valid_txnid;

function check_price($price, $id){
	$valid_price = false;
	//you could use the below to check whether the correct price has been paid for the product
	$sql = mysql_query("SELECT amount FROM `products` WHERE id = '$id'");
	if (mysql_num_rows($sql) != 0) {
		while ($row = mysql_fetch_array($sql)) {
			$num = (float)$row['amount'];
			if($num == $price){
				$valid_price = true;
	return $valid_price;
	return true;

function updatePayments($data){
	global $link;
	if (is_array($data)) {
		$sql = mysql_query("INSERT INTO `payments` (txnid, payment_amount, payment_status, itemid, createdtime) VALUES (
				'".$data['txn_id']."' ,
				'".$data['payment_amount']."' ,
				'".$data['payment_status']."' ,
				'".$data['item_number']."' ,
				'".date("Y-m-d H:i:s")."'
				)", $link);
		return mysql_insert_id($link);

Step 6 – Setting Up The Payments Table

To store payment details in the database a payments table must be created in your database. The following MYSQL code will create a payments table.

 `txnid` varchar(20) NOT NULL,
 `payment_amount` decimal(7,2) NOT NULL,
 `payment_status` varchar(25) NOT NULL,
 `itemid` varchar(25) NOT NULL,
 `createdtime` datetime NOT NULL,

Step 7 – Sandbox Testing / Going Live

PayPal Sandbox offers all of the functionality of PayPal, but the information involves all “Fake accounts” created by the developer. You can create fake buyer and fake seller profiles, then test your PayPal integration through your development website.

During the testing phase of the development process the PayPal links should be prefixed to www.sandbox.paypal.com. You can visit the PayPal Developer website and sign up for a free PayPal Sandbox account

Once the payment process is ready to be used by real customers you will need to remove the sandbox from each PayPal link to www.paypal.com.

That’s it; you’re ready to start taking payments online through your website.

PayPal Integration – Source Files

Download source files

Written by Dan Lawson

Dan is a Web Developer and (self proclaimed) Fifa skills maestro at Evoluted. He spends most of his time developing attractive and engaging websites whilst avoiding the peer pressure of drinking tea or coffee. He enjoys watching Manchester United in his spare time and is the 6 time office Fifa champion. Read more posts by Dan Lawson

Free social media icons for every subscriber

Sign up to our mailing list to have new updates delivered straight to your inbox. Every subscriber will get a free pack of social media icons!


  1. Vixka Studio

    March 02, 2011 at 9:23 am

    Wow, this article is so useful. I’m trying to make custom payment using Paypal. 🙂

    • rama krishna

      July 21, 2011 at 1:47 pm

      Hi, Its very cool code. I was successfully run the code. Thanks .

  2. Nick

    March 23, 2011 at 5:47 am

    Thank you for this, will be extremely useful. One thing though in the SQL, it says `itemid` int(6) varchar(25) NOT NULL, so which one is it? =)

    I’m new to alot of this but int and varchar together return errors in the syntax and I’m guessing you can’t have it as both?

    Thanks again!

    • team

      Dan Lawson

      March 23, 2011 at 9:19 am

      Thank you for highlighting that error Nick. The correct data type should be varchar(25). The article and source code have been updated.

      • Ranjit

        April 03, 2012 at 12:48 pm

        Very Nice Document.

  3. riccardo

    April 04, 2011 at 8:19 pm

    Hi Dan,
    I’m new to this but finally I’ve found your article because sounds so useful for me.
    I’ve a question: in your example do the customers have a paypal account or they can use even credit cards?
    I my previous version (without the paypal feedback) I’ve simply linked the page “” in this way.
    May I do the same putting the right paypal settings?
    thank you in advance
    Riccardo (Italy)

    • team

      Dan Lawson

      April 18, 2011 at 8:07 am

      Hi Riccardo,
      Customers do not need to have a Paypal account to purchase items using this system. They have the option to register and create an account or simply enter their credit/debit card details to complete the purchase.

      • Riccardo

        July 05, 2011 at 11:05 am

        dear Dan,
        I have another question.
        I’m making a test using sandbox but when the paypal window payment appears the customer needs a paypal account, I mean .. he can’t use a direct payment via credit card unless he makes a paypal account registration.
        Any chances to configure params in order to avoid the paypal account registration?
        thank you in advance

        • Rob Petrie

          November 15, 2011 at 6:28 am

          @Riccardo (anyone else who wants to know more about using credit cards with PayPal):

          Hate to say this, but PayPal doesn’t let you submit credit card information directly via an API. You (e.g., the user) are ALWAYS taken to a PayPal interface at some point during the process.

          If you are wanting to avoid having the user know you are using PayPal, you might want to consider AuthorizeNet, TrustCommerce.com or a similar payment gateway. Yes, they charge monthly fees, but depending on the volume of your transactions it may be worth it.

          • tim

            December 31, 2011 at 5:15 pm

            That is not entirely correct, Rob. If you use THIS method of initiating a transaction (sending the payment request to PayPal via a link with variables) then you WILL have to make your payment on PayPal’s site.
            PayPal does offer other options (paid options) that allow you to process cards directly from your site, with underlying processes invisible to the user. Website Payments Pro (https://www.x.com/developers/paypal/products/website-payments-pro) is one such option.

  4. Subramanyam

    May 05, 2011 at 3:43 pm

    Really awesome work.Thanks a lot,this helped me very much.

  5. JoeBob

    May 21, 2011 at 1:50 pm

    Trying to work with this in a test mode, but after filling in the form, I am taken to “payments.php” which displays all of the code in the browser window, rather than taking me to the paypal sandbox. It seems it’s not running the PHP script, but instead displaying it. Any idea what I’m missing?

    • team

      Dan Lawson

      May 23, 2011 at 8:29 am

      Hi JoeBob, Are you testing this locally? If local then PHP requires a free service such as XAMPP or WAMP to run PHP pages.

  6. Shaun

    May 21, 2011 at 8:16 pm

    Hey Dan, thanks so much for this article – developed a credit system using the IPN for my site in about an hour thanks to you!

    • team

      Dan Lawson

      May 23, 2011 at 9:07 am

      No problem, glad you got it working.

  7. Ashok

    May 25, 2011 at 7:07 am

    Hello Dan
    How can I add multiple items in a paypal transaction? This should show multiple items in paypal payment screen.


    • team

      Dan Lawson

      May 25, 2011 at 9:24 am

      Hi Ashok,

      To send multiple items to Paypal IPN you must first alter your HTML so that:

      <input type="hidden" name="cmd" value="_xclick" />
      is changed to:
      <input type="hidden" name="cmd" value="_cart" />

      You can then pass through the Item Name and Item Number as follows:

      item_number1 = 1;
      item_name1 = "Product 1";
      item_number2 = 2;
      item_name2 = "Product 2";
      item_number3 = 3;
      item_name3 = "Product 3";

      You can also add ‘amount1, amount2 etc..’ to specify individual prices per item. These variables should then be added to the $querystring variable and passed to Paypal.

      More details in the documentation.

      • Shannon

        February 21, 2012 at 3:27 am

        Is _xclick/_cart paypal api variables or are they defined by the developer?

  8. Xahyd

    May 30, 2011 at 7:08 am

    Nice tutorial, but i didn’t get where exactly the following 3 links are used. Please can you explain:

    $return_url = ‘http://example.com/payment-successful.htm’;
    $cancel_url = ‘http://example.com/payment-cancelled.htm’;
    $notify_url = ‘http://example.com/paypal/payments.php’;

    • team

      Dan Lawson

      May 31, 2011 at 9:11 am


      The $return_url is used on line 42 ‘Append paypal return addresses‘. This is a page on your web server that is displayed after the Paypal transaction is complete.

      The $cancel_url on line 43 is a page on your web server that is displayed if the user cancel’s the Paypal transaction from the Paypal window.

      The $notify_url is the path of the payments.php page on your web server. In the example this is located within a Paypal folder.

      • Xahyd

        May 31, 2011 at 2:58 pm

        thnx for describing
        i hav a prob with this code, when i make transaction using sandbox i m transfered to success page but my database is not updated according to it.
        mean to say there is some prob in ipn section

        • team

          Dan Lawson

          May 31, 2011 at 3:08 pm

          Do you have an example of the code you are using to update your database? If the Paypal IPN is returning back to your $return_url then this would assume the problem is with the database code.

          • Xahyd

            June 01, 2011 at 11:56 am

            thnx for quick reply.
            actually i email my self and update record in db. if there is some problem with query, at least it must sent email.
            may be code after the following lines didnot work:
            if (strcmp ($res, “VERIFIED”) == 0)

            but i receive payment status “Completed” on success page.

  9. Vikram

    May 30, 2011 at 1:18 pm


    We are trying to send Unit Price and item number for multiple items to paypal. But everytime it shows grand total instead of unit price under the column of UNit price.

    Any suggestions?

    Vikram R

    • team

      Dan Lawson

      May 31, 2011 at 2:56 pm

      Hi Vikram, Do you have a demo online anywhere that I can view the problem. It sounds like you are missing out a required parameter in the query string that is being sent to Paypal.

  10. Dave

    June 03, 2011 at 2:20 am

    Thanks for the great script

    After the payement, i get this error

    The requested method POST is not allowed for the URL

    the return url into a https
    is that the problem ?

    Can you help ?

    • team

      Dan Lawson

      June 06, 2011 at 3:25 pm

      Hi Dave,

      This sounds like you have set your $return_url to a .htm or .html page.

      Try using a .php page as your $return_url.

  11. frz

    June 06, 2011 at 12:20 pm

    Great tutorial Dan!

    I’m using Paypal sandbox, after I submit the payment nothing happens, it just shows me the success page and does not update the database. Please help.


    • team

      Dan Lawson

      June 13, 2011 at 5:22 pm


      Are you using the exact same code as posted in the example or have you changed it in some way?

      To test if the updatePayments function has been reached you could add a mail function In before it is called.

      You may also want to try testing online rather than locally as this can sometimes lead to unexpected errors.

      • Taylor

        December 17, 2011 at 2:32 pm

        I’m having the same problem. I used the exact same code, I just inserted my information for the database variables and paypal settings. I get the success page in paypal sandbox but nothing is added to my database. The only way I can get back to my site’s success page is by clicking the “Return to Taylor’s Test Store” link on the confirmation page. Is that what is supposed to happen? I’m pretty new to all of this so I could just be missing something. Please help

        • team

          Dan Lawson

          December 19, 2011 at 10:16 am

          Hi Taylor

          Can you confirm that you are testing the Paypal code on a live server that is reachable by Paypal IPN.

          • Taylor

            January 02, 2012 at 2:26 pm

            I do have it uploaded to my live server which should be reachable by the IPN. is there a way to test if the server is reachable?

  12. Isaac

    June 13, 2011 at 5:26 am

    Hi Dan, I love your tutorial!

    However I have a couple questions to ask as I’m new to this.

    I see that your payments.php is receiving $_POST[‘custom’] so does that mean that if I pass in at html it will return me 444 (if 444 is my customer ID in my website so that I can update him as paid)? Also can this system be used for subscription on paypal?

    I also would like to know do we remove this two lines:
    14 $item_name = ‘Test Item’;
    15 $item_amount = 5.00;

    when we are going to deploy it live?

    • team

      Dan Lawson

      June 13, 2011 at 4:47 pm

      Hello Isaac,

      The ‘custom’ variable can be any value that you wish to transfer between the payments.php page and the response from Paypal. In your case the ID 444 could be used to update the customer as ‘paid’.

      This system can be used for subscription payments however the sample code Is not currently set up to do so. You can view which extra parameters you need at the paypal website here.

      The $item_name and $item_amount variables are to determine what the Paypal payment is for and how much. They can either be pre-set in the payments.php code or brought in dynamically (The user selects a product to purchase on the website).

      • Isaac

        June 14, 2011 at 2:14 am

        Hi Dan,

        Thanks for the clarification. Therefore so to speak I can just generate the code from paypal’s website standard button and throws in those extra parameters in the html submission form ya? Just make sure at ipn handler and grab them

        • team

          Dan Lawson

          June 17, 2011 at 11:26 am

          That’s right Isaac,

          The paypal standard button is performing the same IPN request/ response as this sample code.

  13. Kamaraj

    June 14, 2011 at 7:11 pm

    Hi Dan,

    I have implemented your code in to my Joomla website.
    URL: http://singaporetamilwriters.com/wtwc/index.php/register-here/registration-form-locals

    I have tested with sandbox many times. It was working fine.
    When I am testing with PayPal actual account, payment is made, but the functions inside this
    if (strcmp ($res, “VERIFIED”) == 0) { } condition is not working.

    if (strcmp ($res, “VERIFIED”) == 0) {
    /* Not working */
    else if (strcmp ($res, “INVALID”) == 0) {
    /* Working */

    Please help me.

    Thanks in advance.

    • team

      Dan Lawson

      June 17, 2011 at 11:25 am

      Hi Kamaraj,

      Could you place the following debug code into your /payment-successful.php file:

      echo "<pre>".var_dump($_POST)."</pre>";

      This will output all the Paypal response variables. Could you confirm the [pending_reason]?


  14. Jason Carroll

    June 20, 2011 at 8:33 am

    Hello Dan,

    Thank you for this great tutorial, I have one question so far, step 3 and 4 have the same file name but different file content ? Not sure if I am missing something here.

    • team

      Dan Lawson

      June 20, 2011 at 10:21 am

      Hi Jason,

      The payments.php file is broken up into two parts for the purposes of explaining what each section does in this tutorial. If you open the sample files here it may become clearer.


      • Jason Carroll

        June 20, 2011 at 11:10 am

        Thank you Dan.

  15. Joseph

    June 22, 2011 at 7:57 am

    Hi Dan,

    I’m new to php. Is it possible to change the currency to MYR?

    Thanks in advance.

    • team

      Dan Lawson

      June 22, 2011 at 10:13 am

      Hi Joseph,

      To change the currency to Malaysian you would need to change the currency_code variable to MYR.

  16. Manjula

    June 26, 2011 at 7:26 am

    Thanks for your guide…. this document is clear and really helpfull

  17. riccardo

    July 06, 2011 at 12:51 pm

    Dear Dan,
    I’m experiencing a problem: the “fsockopen” fails (I did not change your example).
    The paypal transaction is completed and successful. here is the $_POST variable

    array(33) { [“mc_gross”]=> string(4) “5.00” [“protection_eligibility”]=> string(10) “Ineligible” [“payer_id”]=> string(13) “NUZDBE7UATCZG” [“tax”]=> string(4) “0.00” [“payment_date”]=> string(25) “04:49:15 Jul 06, 2011 PDT” [“payment_status”]=> string(9) “Completed” [“charset”]=> string(12) “windows-1252” [“first_name”]=> string(8) “Riccardo” [“mc_fee”]=> string(4) “0.52” [“notify_version”]=> string(3) “3.1” [“custom”]=> string(0) “” [“payer_status”]=> string(10) “unverified” [“business”]=> string(30) “info_1309859245_biz@zenweb.biz” [“quantity”]=> string(1) “1” [“payer_email”]=> string(19) “r.rrrrrr@gmail.com” [“verify_sign”]=> string(56) “AAPxdwqA6Qyxa8LzcNiBQOchbiL-AHCr7TjQpRrJ29bkB1Iqw0ozjV.o” [“txn_id”]=> string(17) “32978634XL760873V” [“payment_type”]=> string(7) “instant” [“last_name”]=> string(7) “Rossi” [“receiver_email”]=> string(30) “info_1309859245_biz@zenweb.biz” [“payment_fee”]=> string(0) “” [“receiver_id”]=> string(13) “JB58DVUF63N7A” [“txn_type”]=> string(10) “web_accept” [“item_name”]=> string(45) “Communication Conference Fee” [“mc_currency”]=> string(3) “EUR” [“item_number”]=> string(4) “K143” [“residence_country”]=> string(2) “IT” [“test_ipn”]=> string(1) “1” [“handling_amount”]=> string(4) “0.00” [“transaction_subject”]=> string(45) “Communication Conference Fee” [“payment_gross”]=> string(0) “” [“shipping”]=> string(4) “0.00” [“merchant_return_link”]=> string(44) “Torna al sito Riccardo Rossi\’s Test Store” }

    thank you in advance

  18. George

    July 12, 2011 at 12:02 pm

    How can I append other form values like Name, Email etc to the database. I am losing all the data once it gets redirected to paypal sandbox

    • team

      Dan Lawson

      July 12, 2011 at 1:37 pm

      Hi George,

      You would need to insert your form data into the database before the initial Paypal querystring is sent. The usual process is to insert the form data into the database, retrieve the ID of the newly inserted row then use this as the custom variable in the $querystring.

      This will then be returned by Paypal so that you can query your database for the information.

      Hope that helped,


      • George

        July 12, 2011 at 3:08 pm

        Thanks Dan

  19. Madav

    August 03, 2011 at 2:30 am

    Hi Dan,

    Sorry I’m new in e-commerce. In the code you gave us, when the paypal transaction has confirmed, the browser return to the payments.php but nothing happend. Just show a BLANK PAGE and the records did not insert in the database. No errors and no clues. Can you help me…? Thanks in advance.

    • team

      Dan Lawson

      August 10, 2011 at 1:35 pm


      The code has been updated with the changes listed at the top of the page. If you could try these and see if you are still having any problems.


  20. Bill

    August 19, 2011 at 5:27 am

    Hi Dan,
    Pretty good tutorial. I tried your script and it was doing fine all the way to payment successful page. I looked at my sandbox account and all the payments made are there. However, I am puzzled (extremely), why the database are not being updated. I tested it over 10 times, but no luck.

    Thanks for your help..

  21. Bill

    August 19, 2011 at 5:33 am

    Hi Dan,
    I’m sorry for double posts, but I really have to let you know that it is working on my side now.

    Great script…thanks for your hard work..


  22. Bill

    August 20, 2011 at 7:59 pm

    Hi Dan,
    Just wondering, is there any way we can make this script to function handling membership payments?

    Say, I have a mysql table | id | member | monthly_due | status | rec_date |. Member clicks on the pay now button to pay, and then script upgrades database to record payment made by member.

    Just a thought 🙂


    • team

      Dan Lawson

      August 22, 2011 at 10:31 am

      Hi Bill,

      You can pass any values through to Paypal using the ‘custom’ field. With this you are able to pass the member_id through to paypal using:

      // Append querystring with custom field
      $querystring .= "&custom=".USERID;

      If the response from Paypal is then successful, you can update the membership table for that member_id.

      Hope that helps,


      • Bill

        September 02, 2011 at 8:46 am

        Hi Dan,
        Thank you very much for speedy reply. Yes, I will do as what you have suggested and post an update here.

  23. Aash

    August 24, 2011 at 1:00 pm

    Hi Dan,

    Mind blowing article indeed!!

    Really appreciate your efforts in creating such an awesome article on paymentGateway Integration using paypal.

    I am just wondering if you can please also supply the same in classic ASP?

    Thank you!

  24. Chris

    August 31, 2011 at 4:41 pm

    Hi Dan,

    This is an excellent tutorial I came across while looking for somethin entirely different. I’ve now bookmarked your site and will do doubt be a frequent visitor.

    Top class mate, well done!

  25. Hengst

    September 08, 2011 at 7:13 pm

    Hi Dan, I’m working on integrating your script and have it almost working however I’m having a problem with database being populated with “payment status pending”.

    Any ideas?

    • Hengst

      September 08, 2011 at 8:55 pm

      Nevermind my posts. everything worked. problem was the sandbox. created all new testaccounts and all was fine.

  26. Hengst

    September 08, 2011 at 7:41 pm

    Hello Dan,

    In the sandbox mode the request to paypal and back is ok but several identical database entries are created with payment status “pending”.

    Debugging gives me ” Verified Responsedata = “. It looks like something is missing. but what?

  27. Jeremy

    September 15, 2011 at 5:36 pm

    Nice one! Worked straight off.

  28. Anand

    September 16, 2011 at 4:44 pm

    Dan, I have just one line to say “you are awesome!.”. I have not seen any article explained this simple and easy to implement as you have done. Great work, it worked like a charm

  29. denish

    September 20, 2011 at 7:27 pm

    All are cooool here, awessome actly

    but just one issue is that,
    After payment success , my page is not redirecting to success-payment.php


    i am testing on sendbox’s accounts..

    Any suggestion

    • team

      Dan Lawson

      September 21, 2011 at 9:03 am

      Hi Denish,

      Try setting your success page to a .htm page rather than a .php page and see if that works.

      • denish

        September 21, 2011 at 7:18 pm

        thankx for quick reply

        .htm, .html … not working…
        still page is not redirecting to success page…

        and one more thing, i was forgot to ask…
        that my else part (response part) is not working in payments.php…
        after payment success, i didnt get any mail , not DB insertion of orders etc

        have set mail just after ELSE
        //response part

        but m not getting any mail…

        plz give suggestion…

        thank you

  30. Jim

    September 27, 2011 at 7:58 pm

    Hi..great tutorial. I am trying to allow my customers to pay any amount they want for a service with a minimum..for example, I want the user to pay what they feel like paying with as long as it is at least 5$..can I pass this to my paypal account in a way that won’t let them change it? thnx!

    • team

      Dan Lawson

      September 28, 2011 at 9:19 am

      Hi Jim,

      You would simply need to have an input field on your initial form that could be a textbox or a select box, like so:

      <input name="amount" type="text" value="5.00" />

      In your payments.php page that builds the $querystring you could do a php check to verify that the amount variable from the form is greater than or equal to 5.

      You would then need to change $item_amount = 5.00; to reflect the user entered amount $_POST[‘amount’].

      Hope that helps.

      • Jim

        September 29, 2011 at 12:08 am

        I sort of snuck up on that same answer after some trial and error…thanks so much, you rock!

  31. Jim

    October 02, 2011 at 2:58 am

    Dan: I wonder if I can ask you another question..I modified the script so that the user inputs their own amount which is then passed onto the payments.php script by setting the amount equal to the $_POST from the form that asked how much they wanted to pay. It worked great…just like I wanted it to. I then made a few other changes and it stopped working so I went back to the file I had just been using and it no longer works! very strange! Any idea of how to figure out what is happening?

  32. Jim

    October 02, 2011 at 6:38 pm


    Is it sometimes not ok to use localhost in order to let the script find the database? I notice that when I use the actual server name provided by my hosting company, I can connect to my database, but not run the script..and when I use ‘localhost’, I can run the script it doesn’t see the database..I’m totally baffled..!

  33. Murugan

    October 03, 2011 at 6:31 am

    Nice tutorial Dan Lawson

  34. Louis

    October 12, 2011 at 7:28 pm

    Hello Dan,

    Such an awesome tutorial, really. I was able to set it up and customize it in less than an hour. Only one thing I haven’t been able to figure out: Is there any way to disable the registration when a user pays by Credit Card? Currently, he has to enter an E-Mail and password when entering his Credit-Card details, which bothers my client.

    I have a verified business account and E-Mail and I set “Account Optional” in the PayPal-settings, yet the user still has to create an account when entering his CC-details. Anything that I missed?

    • team

      Dan Lawson

      October 13, 2011 at 9:12 am

      Hi Louis,

      Thanks for the feedback. PayPal should automatically allow you to pay by your PayPal account or credit card. This sometimes will only display the login box and no credit card details when there is a PayPal cookie set. Has the user tried refreshing their browser cache before making a payment?

  35. Dave

    October 14, 2011 at 10:14 pm

    Hi Dan!

    This is really very helpful. I am new to this and your explanation is awesome.

    I was creating a small online application where users enter their email and the mobiles phone’s IMEI number.

    I want to know how to pass the email id and the the IMEI number to paypal and once the payment is successful I need to make use of the email and the IMEI number.

    How can I be able to do that. Would you help me?

    Thank you!

    • team

      Dan Lawson

      October 17, 2011 at 8:58 am

      Hi Dave,

      One option would be to pass the IMEI number into the initial $querystring using the custom parameter:

      $querystring .= "custom=".$imei_number;

      This could then be retrieved after the paypal payment using $_POST[‘custom’].

      The e-mail address can also be retrieved using $_POST[‘payer_email’].

      Alternatively you could pass both the e-mail and the IMEI number into the custom parameter:

      $querystring .= "custom=".$user_email."---".$imei_number;

      You could then break this string into an array using:

      $custom_array = explode("---", $_POST['custom']);

      Hope that helps.

  36. bhavesh

    October 20, 2011 at 8:08 am

    Hi Dan!

    This is really very helpful. I am new to this and your explanation is awesome.

    But one problem is that i don’t know how to use this code in my website please help me.


  37. Adeel Ishfaq

    October 25, 2011 at 3:49 am

    Hi Dan,

    Nice tutorial man, awesome instructions, easy to learn paypal integration for a beginner through your article.

    Thank You

  38. prasanth mathew

    November 03, 2011 at 1:34 pm

    Hi Dan,
    Very good tutorial.
    thanks a lot.

  39. dran

    November 06, 2011 at 11:41 pm

    hi, one question, can I test this scripts on localhost, using WAMP

    • team

      Dan Lawson

      November 07, 2011 at 10:26 am

      Hi dran,

      I would test the script on a live server rather than WAMP.

      Paypal requires a reachable return URL rather than a local file.

  40. Amar

    November 15, 2011 at 10:53 am

    Hi Dan,great job.I have integrated paypal.All going well.After payment had done payment-successfull.htm is also showed.But i have a problem that the values are not inserted into database although i have already created a table.I don’t have any clue why this is happening.Please help me..
    Thanks in advance…..

    • Amar

      November 15, 2011 at 12:42 pm

      And I have another problem in paypal account Payment status shows Unclaimed.

    • team

      Dan Lawson

      November 15, 2011 at 1:02 pm

      Hi Amar,
      Can you confirm that you are using a verified Paypal Business account and testing on a live server?

      Both these are needed to receive a Verified status.

      • Amar

        November 16, 2011 at 5:42 am

        Hi Dan,
        I am using verified Paypal personal account and testing on localhost.That might creating the problem for status.Is it also creating for the database problem i.e. data not inserted into database?

        • Amar

          November 16, 2011 at 8:32 am

          And i have another problem is that when i changed to [value=”_cart”] it detects error .I don’t understand why this is happening.Thanks in advance…

          • team

            Dan Lawson

            November 16, 2011 at 10:04 am

            PayPal requires a reachable server for the resquests and responses. Try uploading your website to a live server and try then. Let me know if you have any problems.

      • Amar

        November 18, 2011 at 5:44 am

        Thanks DAN,I uploaded in a live server then i got the problems solved.But when i changed to [value=”_cart”] it detects error .

  41. matvinculado

    November 24, 2011 at 9:23 am

    Awesome! 🙂

  42. piplin

    November 24, 2011 at 4:31 pm

    So useful!!
    You are my saviour in the issue!!
    Very thanks!! ^_^

  43. Juan

    December 03, 2011 at 6:21 pm

    Thank you very, very much, this is very helpful, I couldn’t find a decent tut for my ‘paypal’ problem, and this one simply rocks 😉

    thnx from Spain

  44. matvinculado

    December 06, 2011 at 4:45 am

    hi, im working on my integration now, the payment is working well however the newly added row line from database is not being updated.

    please help me:

    //get transactions number fo id.
    $transactions=mysql_query(“select paypal_payment,cashsense_payment from transaction_numbers”);

    $tnid=$pppayment + 1;

    //update webstatus of user
    $tnudpate = mysql_query(“UPDATE transaction_numbers SET paypal_payment = ‘”.number_pad($tnid,20).”‘ “);
    $newpayments = mysql_query(“INSERT INTO payments VALUES(”,'” .$ppuid. “‘,’no’,’PAYPAL’,'” . $current_date . “‘,'”.$userid.”‘,'”.$_POST[‘bpbuycredits’].”‘)”);

    / Append querystring with custom field
    $querystring .= “&custom=”.$ppuid;

    //from other on dataupdating after the payment

    // Validate payment (Check unique txnid & correct price)
    $valid_txnid = check_tn($data[‘custom’]);
    $orderid = updatePaypalPayments($data);
    // Payment has been made & successfully inserted into the Database
    $updateBPPayment = (“UPDATE payments SET successfulpayment=’yes’ WHERE paymentid='”.$data[‘custom’].”‘ “);


    hope you can help me, i have my own id’s not using txn_id. and it will be also a great help if you can give some code how to insert the txn_id before redirecting to paypal.

    thanks 🙂

    • matvinculado

      December 06, 2011 at 8:17 am

      never mind my last post got it working, honest mistake, forgot mysql_query 🙂

      thanks and very great post 🙂

  45. Bulbul

    December 14, 2011 at 7:14 pm

    Really great tutorial Dan !!

  46. Dave

    December 15, 2011 at 8:03 pm

    Hey Dan!

    This one worked like a charm. But the problem is after the payment is made it does not automatically redirect to the payment-success.htm page.

    They should click on go to the store’s page on the paypal page in order to get redirected.

    Can you help me how to get them redirected automatically?

    Thank you!

  47. marc

    December 20, 2011 at 1:39 pm

    Hi Dan,
    first of all thank u for ur great tutorial.
    Anyway .. got a problem using sandbox.

    Anything is working – I mean the transaction is done correclty – but
    fsockopen returns $errstr = “Success” so the code cannot continue.
    Could be a sandbox problem?

    $fp = fsockopen (‘ssl://www.sandbox.paypal.com’, 443, $errno, $errstr, 30);

    if (!$fp) {
    mail(‘marc.stefan1968@gmail.com’, ‘fsockopen error’, $errstr);
    } else {

    thank you in advance

    • team

      Dan Lawson

      December 20, 2011 at 3:50 pm

      Hi Marc,

      Is your Paypal IPN code on a live server that can be reached by Paypal (not a localhost testing server) ?


      • marc

        December 20, 2011 at 4:43 pm

        Hi Dan,
        thx for your reply.

        Yes it is. It’s a regular domain (linux + MySQL under Apache)

        • marc

          December 21, 2011 at 11:53 am

          hi Dan,
          I don’t want to stress u but I really need to solve this issue.
          The $errno returns 0 and the $errstr returns “success”, so apparently the fsockopen works. May I consider as successful the value 0 and Success intead of if (!$fp) { } ?
          thank you again

  48. Sandy

    December 20, 2011 at 2:55 pm

    Thanks for this tutorial, it is amazing! Just what I was looking for. Once quick questions, do you have to pass over the customer details (address fields etc)? I am looking for a solution that will simply have a “pay via paypal” button at the end where the user goes off to paypal and just signs in. It seems pointless to send over the address details when they can be obtained from paypal? I’m just thinking of convenience for my customers.

    • team

      Dan Lawson

      December 20, 2011 at 3:48 pm

      Hi Sandy,

      No you don’t need to send the address fields to Paypal. You can get the customers address details from the Paypal $_POST response instead.


      • Eric

        February 09, 2012 at 8:21 pm

        How would you code this so that you can insert any additional variables into the database? There are several other form details that I need to add, but I can’t get it to work via a $_POST

        • team

          Dan Lawson

          February 10, 2012 at 10:17 am

          Hi Eric,

          You have two options:

          Either insert the data into the database before the request is sent off to PayPal and set the status to ‘paid’ on a successful transaction.

          You could also pass the variable through in the Custom field like so:

          $querystring .= "&custom=".$var1."-".$var2."-".$var3;

          You can then retrieve these values after payment by:

          $custom = array();
          $custom = explode("-", $_POST['custom']);
          // You can now reference each variable as

          Hope this helps.

  49. John Milton

    December 21, 2011 at 7:21 am

    Hi Dan!

    Your tutorial is really amazing. The code works perfectly. Just wanted to know if the customers can be redirected automatically after payment to the success page without click on “Return to customer site”.

    Is there a way to accomplish this? If yes, how can I do make the customers automatically redirect?

    • team

      Dan Lawson

      December 21, 2011 at 10:00 am

      Hi John,

      Thanks for the feedback. There is a way to accomplish the automatic redirect but it has to be set in the Paypal admin interface.

      Here is a quick guide on how to do it: https://www.paypal.com/cgi-bin/webscr?cmd=p/mer/express_return_summary-outside

      • John

        December 23, 2011 at 6:23 pm

        I just tried the auto redirect method Dan. But the auto redirect dont pass the custom variable values back to success page. The success page doesn’t grab the variables when I switched the auto redirect button “on” in paypal options method.

        If I dont use that auto redirect the variables can be grabbed and displayed. So, Can you tell me who can I pass them using the auto redirect method.

        • team

          Dan Lawson

          January 03, 2012 at 10:12 am

          Hi John,

          When the success page is live you will need to use the $_REQUEST array to retrieve your data as Paypal changes the method to GET rather than POST.

          Try echoing out:

          echo "<pre>".var_dump($_REQUEST)."</pre>";

          on your success page to see the variables.

  50. dheeraj

    December 21, 2011 at 6:04 pm

    Hi best article. This is very use full.
    Will you suggest about the tax and other charges in paypal.

  51. Modular

    December 23, 2011 at 2:08 am

    Awesome tutorial – brilliantly elaborate and extremely practical code without any error (testing on local server, Xampp at the moment – hopefully on live server would be fine.) Your post made my day and save lots of time. Keep up your excellent work.

    Merry Xmas and Happy New Year 2012, everyone 🙂

  52. rich

    December 29, 2011 at 2:49 am

    hello mate is there any way possible to pass the whole shopping cart to paypal, got something working but its only passing one item to paypal

    • team

      Dan Lawson

      January 03, 2012 at 10:16 am

      Hi Rich,

      Yes you can pass the whole shopping cart through to Paypal.

      Look here for the ‘item_name x’ variable.

  53. kiko

    January 13, 2012 at 9:43 am


    What if I am going to use paypal.com instead of sandbox.paypal.com? I want to integrate the real paypal into my website. Thanks in advance!

    • team

      Dan Lawson

      January 13, 2012 at 11:43 am


      You would simply need to remove ‘sandbox’ from the URL in payments.php

  54. param

    January 14, 2012 at 6:34 am

    Thanks a lot man.

  55. Sandy

    January 14, 2012 at 4:10 pm

    Hi Don,
    Nice Tutorial, I really appreciate. I Have a bit problem. This error is appear wen we click on Submit payment button. Do you Have any idea ?
    Thanks for Suggestion.
    Warning: Cannot modify header information – headers already sent by (output started at /home/unleashs/public_html/payment/payments.php:1) in /home/unleashs/public_html/payment/payments.php on line 51

    • team

      Dan Lawson

      January 16, 2012 at 10:08 am

      Hi Shandy,

      It sounds like you have a debug ‘echo’ somewhere in your code. Try debugging each line until you find the problem echo.


  56. Unni

    January 17, 2012 at 8:30 pm

    Hello Dan…
    Just went through your tutorial. And its very nice and clear. Thanks. Now I am about to try it in real.I have a doubt.1> If i select Personal account then is it possible for my customers to pay via debit card? or is Premier account must for this?
    2> Is there any pros or cons between them?
    3>If i am setting up a small buy option without much buyers and no much huge transactions then which should i opt for.

    I Googled it up but it totally confused me. 🙁 It would be very helpful if you could clear this thing. 🙂
    Thank you Dan…

    • team

      Dan Lawson

      January 18, 2012 at 10:41 am

      Hi Unni,

      Thank you for your comments. To use PayPal’s IPN service you must either have a Premier or Business account. These are free to set-up but charge a small percentage fee per transaction.

      Hope that helped.

  57. John

    January 24, 2012 at 3:58 am

    Thank you for this useful information. It helps a lot.


  58. Mint

    January 28, 2012 at 4:31 pm

    Hello Dan!

    Excellent work, just like what i’ve been looking for, I need to do up a paypal integration with my school project, and i found this! 😀

    Anyway, really appreciate this effort, and it works for me, I tried in sandbox mode, all the way until the payment is made, the redirection are good,but it did not update my database, did not insert into my payments table and it did not notify me on the page when the payments are made, do you have any idea where is the portion i should look for to edit the codes for notifications to the user when they made a payment?

    Thanks in advance 🙂


  59. edgar

    February 01, 2012 at 1:22 am

    Great article about paypal integration. Thanks for this article!!. 🙂

  60. Sebosa

    February 01, 2012 at 8:17 pm

    Your tutorial is really very interesting.I want a help..i have created a subscribe button from paypal account and placed it in my website.I would like to use this button to subscribe and pay the amount by the user and return back to my website with an id because i want to save a flag status if he /she pay to my DB.

  61. Çağlar

    February 01, 2012 at 10:12 pm

    Very usefull article, thanks for writing it ^^

  62. Sergio

    February 12, 2012 at 2:52 am

    For those who wish to submit multiple items to paypal cart, this article could be a good friend. https://www.paypal.com/cgi-bin/webscr?cmd=_pdn_howto_checkout_outside

  63. Sergio Felix

    February 17, 2012 at 7:47 am

    Hey Dan,

    Just wanted to thank you for this amazing resource my friend.

    By far the best article I’ve seen on integrating PayPal with PHP&MySQL, hope I can make it work now! 😉


  64. Rob

    February 20, 2012 at 9:32 pm

    Hi Dan, brilliant guide !!

    Could I ask you or anyone of how I can get the “custom” field data back from when a buyer clicks (cancel) to bring them back to my site (cancel_return). The data isn’t in the POST data. ($_REQUEST[‘custom’])…?

  65. Paul Angelo Silvestre

    February 26, 2012 at 11:54 am

    Hi Dan! great tutorial! i just need something.. i ran this code perfectly and it worked perfectly.. but the thing is.. after a successful payment, it will go back to my website.. but, it doesnt update a value from my website.. like for example.. in my website i got 0 points.. and to have a point/s i need to pay like $3 for 5 points.. what i would like to do is.. after a successful payment.. i will be redirected to my site having the 5 points.. thanks!

  66. Lakshman

    March 01, 2012 at 4:06 pm


    The article is really awesome, thanks for posting. very useful

  67. Ian.J.Gough

    March 01, 2012 at 4:35 pm

    Works like a dream and is very easy to modify and understand. Thank you for writing and sharing your code.

  68. Likhit

    March 08, 2012 at 12:16 pm

    Hi Dan Lawson,

    Thanks for this great article,
    I am working on a php project where i need to integrate paypal. I am trying out your code for the same. But I am stuck at the request line: if (!isset($_POST[“txn_id”]) && !isset($_POST[“txn_type”])), can you please tell me where are you setting “txn_id” and “txn_type”. Please reply at the earliest, need to role out on production at the earliest.

  69. Ganesh

    March 16, 2012 at 12:25 pm

    Thank you dude

    This document is very useful 🙂

  70. Daniel

    March 30, 2012 at 8:16 pm

    Hi, Is there any way using this script to output the item purchased (i’m using a buy now button with options like 1 month, 2 moths 3months)


  71. Geoff

    April 04, 2012 at 12:22 pm

    Total quality. Thanks.

  72. Andy

    April 19, 2012 at 5:07 am

    I just wanted to thank you from the bottom of my heart. I appreaciate the time and effort you put into this.

    With the help of your tutorial, a good php book and the internet in general I was able to tweak your script to fit my needs as well as furthering my php education a great deal.

    Again… Thank You!

  73. Stephen – The Review Site Guy

    April 22, 2012 at 10:32 am

    unless my understanding of PHP is off, line 21 of functions.php references a non-existent mysql function:

    if (mysql_numrows($sql) != 0) {

    should be mysql_num_rows, right?

  74. Craig Hopson

    April 23, 2012 at 8:37 pm

    Works, simple!!!!

    Thank you so much for taking the time

  75. Kevin

    April 25, 2012 at 8:41 am


    Thanks a lot for taking the time to write & share this, it works for me just like everyone else.

    The only issue is.. I really don’t know anything about php and I have no idea how to change the currency from £ to €, could you please tell me how this is done?

    • team

      Dan Lawson

      April 25, 2012 at 9:02 am

      Hi Kevin,

      Thanks for reading the post. To change from £ to Euros you will need to change the currency_code value in the form to EUR:

      <input name="currency_code" type="hidden" value="EUR" />


  76. Daniel

    May 03, 2012 at 2:28 pm

    Update: remove the ‘/p/’

    $root = realpath($_SERVER[“DOCUMENT_ROOT”]);
    include “$root/functions.php”;