Paypal, mysql, and php

Posted on 2011-03-14
Last Modified: 2013-12-13

I am new here, and I joined to get some help. What I have so far is a reward shop. What I need is  a donation system where users who donate money to help support the server receives virtual points.

My problem is I am unable to get the donation system to set up! I need to be able to log the username of the person donating and the amount. Then from there update my sql database and award the donor with donor points. But so far I have no luck with the php coding or the paypal IPN. If someone can help me get this project going it would be great!

Edit: I can donate and it updates to my database. but the thing is I don't know how to make it so it updates the right account . My donate table is different from my account table. And all it stores into the paypal table is the transaction id, amount, email, etc. How would I go about programming a code in php where it checks the session to see if the person is logged in, if so then it sends that data(username, id, email) to database. When paypal sends the info back it verifys and updates the points to the right account. Where would I go about doing something like this?
Question by:sky479
LVL 19

Expert Comment

ID: 35127326
Let's see... If I'm understanding you right the problem is that your donation page, after returning from paypal service, loses session user parameters and you don't know how to associate the donation to a user account.

Usually payment platforms are base upon webservices that expect some parameters related to transaction and return different values depending on the result of the transaction.

I supose you probably are sending the execution directly to paypal, and when their service returns your page has lost session data.

What you need to do is:

1) Ask for your users to log onto your system.
2) Send to paypal service the transaction data without losing your current session environment (use an AJAX call, include paypal form inside your page code if user interaction is required for transaction or simply open it in a new window).
3) On paypal service return, from your code, check the value of the response and save data to your database accordingly.
LVL 14

Assisted Solution

by:Scott Madeira
Scott Madeira earned 500 total points
ID: 35128695
I will assume you are a php person and can write code to do the things that need to be done.  If not, then you are biting off more than you can chew with your project.

Here is how I would approach the problem.

1. When a person makes a donation they need to provide three things:  a username, a password and an amount.

2. Take the username and password and create an account for the person in the account table if they don't have one already.  If the username is already taken then they will need to choose another username.  Also, in that table you need to have a unique key field (userID, for example) as the primary key on the table.  you can add address, phone, etc. if you want that info too.

3. Create a donations table that has the following fields (at a minimum):  donationID (primary key and unique), userID (the userID from the account table of the person donating), the amount donated, txnID (the paypal transaction ID), Payment status (status of the donation.)

4. Send the person to PayPal to pay and in the message sent to PayPal include the donationID so you can link the donation to the donations table. I think the IPN field that you can use for this is item_name and item_number but you will need to check the IPN documentation to be sure.

5. In your IPN script that you write you will be looking for the item_number to match the IPN message coming back from PayPal with what you stored in your donation table.  you can update the payment status in your table based on the payment status of the IPN message.

Every time somebody makes a new donation you add a new row to the donations table.

There are a huge number of other details to consider but this outline should get you started in the right direction.  there are lots of IPN scripts available online to help with the post-processing of the payment.

Author Comment

ID: 35129245
Thanks a lot I will try both of your methods and see how it goes. I've been trying for days so I thought I should seek professional help. I got a work frame to work with now, before I was in the dark searching everywhere on what to do. Thanks again and I am going to try your 2 methods and see what I come up with. Will update you guys on how I did it and see if it works.
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.


Author Comment

ID: 35130333 I need the  ipn-listener.php? I have the ipn.php but I don't know if they are similar or not.

Author Comment

ID: 35130404
Okay, if I where to hire someone to help me with this where would I get the help and how much do you guys think it will cost me?
LVL 14

Accepted Solution

Scott Madeira earned 500 total points
ID: 35131352
The sample ipn-listener code from the PayPal web site ( shows you the minimum structure to receive the IPN message from PayPal, send the acknowledgment back to PayPal and shows you where you need to write code to validate the messages and save the information to the database.  You need to have this function in your system.   I don't know what the ipn.php script you refer to is doing so I can't comment on whether you need both or not.

As for hiring somebody to do it?  I'd think it would be a day or two of effort if they had access to all of your code and your servers.  One place to search would be to see who may be available.  What you want is not very complicated.  You may be able to find a college kid that would do it for $20/hr or so and get it done pretty quickly.

I don't know if EE has a projects / employment section or not.
LVL 109

Expert Comment

by:Ray Paseur
ID: 36404366
Not sure if this question is still active, but I have done exactly the thing you are talking about for my church.  We accept donations via PayPal.  In practical terms, we receive about as much money via PayPal as we receive via cash in the collection plate.

We have a separate bank account associated with PayPal donations.  The PayPal IPN script is used to keep a log of donations (although PayPal keeps this information for us, too).  Information available in the IPN script includes the donor's email address, and given the anonymity of church donations, this is all we use to keep track of the donors and the amounts.  Our log of donations enables us to give the donors quarterly and annual statements.

You cannot check a client session in the IPN script.  It is an asynchronous script that is not associated with a client session.  So your design that associates points with donations must use something other than the session.  That is why we use the email address from PayPal as the client identifier.

HTH, ~Ray
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 37313466
This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

Featured Post

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
what do I need to host my own web sites? 13 49
php help 34 58
check mysql insert 12 26
MSSQL - Lock Row from reading by other programs 9 34
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
When table data gets too large to manage or queries take too long to execute the solution is often to buy bigger hardware or assign more CPUs and memory resources to the machine to solve the problem. However, the best, cheapest and most effective so…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

791 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question