leeh14 Posted October 26, 2010 Share Posted October 26, 2010 Hi, I am about to incorporate some PayPal functions to my site and am just asking for some advice before I start. Basically a user is going to enter some data into a form and then be passed to PayPal to pay an X amount, once the payment has been verified I want the information entered in the form (before going to PayPal), to be added to a database. But it seems that PayPal does not allow you to pass multiple (about 13) variables through their system. Is this correct? So what I was going to do is just before the customer goes to the PayPal site, I was going to insert all the data into the database and set a payment status, then once the payment is confirmed re-setting the payment status to paid or non-paid. Is that a good way to do what I want? If not is there a better way? Any help would be great. Lee Quote Link to comment Share on other sites More sharing options...
drisate Posted October 26, 2010 Share Posted October 26, 2010 Yeah thats how i would do it. That whay the only thing paypal needs to send your back is the ID of the member when the paiement is done. Quote Link to comment Share on other sites More sharing options...
micah1701 Posted October 26, 2010 Share Posted October 26, 2010 Yeah thats how i would do it. That whay the only thing paypal needs to send your back is the ID of the member when the paiement is done. agreed, in fact, in your database table, you don't even need a "paid" or "unpaid" status. Just have a field for the transaction ID. If the field is blank in your database, you know the status is "unpaid" Quote Link to comment Share on other sites More sharing options...
leeh14 Posted October 26, 2010 Author Share Posted October 26, 2010 Sweet, well that is pretty much all I needed to hear! I have not yet experimented with this yet, but I can imagine that the thing which will be the hardest is getting hold of the 'ID' field and then sending that off to PayPal, as the ID field is created with auto increment as the data is inserted to the database. Does anyone have a quick idea for how I would be able to get hold of this field before going into PayPal?? Quote Link to comment Share on other sites More sharing options...
micah1701 Posted October 26, 2010 Share Posted October 26, 2010 sure thing, use mysql_insert_id() to retrieve the last inserted ID. <?php mysql_query("INSERT INTO table (col1,col2) VALUES ('val1','val2')"); $new_id = mysql_insert_id(); ?> Quote Link to comment Share on other sites More sharing options...
leeh14 Posted October 28, 2010 Author Share Posted October 28, 2010 Cheers, that seems easy enough and shouldwork fine. The last thing i would like to know is what would happen if say two people where using the site at the same time. Small chance but still worth thinking about? Like will there be a queue as the collect ID is in the same function already being run. Quote Link to comment Share on other sites More sharing options...
micah1701 Posted October 28, 2010 Share Posted October 28, 2010 Cheers, that seems easy enough and shouldwork fine. The last thing i would like to know is what would happen if say two people where using the site at the same time. Small chance but still worth thinking about? Like will there be a queue as the collect ID is in the same function already being run. if you are really concerned about Internet race conditions, where mysql_query() is executed in two different scripts simultaneously and therefore mysql_insert_id() returns the wrong id value, than you could *not* use mysql_insert_id() and instead do a query for the data you just entered. so like: <?php session_start(); mysql_query("INSERT INTO table_name (col_1,col_2,user_token) VALUES ('val_1','val_2','".session_id()."') "); $get_mysql_inserted_id = mysql_query("SELECT `id` FROM table_name WHERE user_token = '".session_id()."'"); $id = mysql_result($get_mysql_inserted_id,0,0); echo $id; Quote Link to comment Share on other sites More sharing options...
leeh14 Posted October 29, 2010 Author Share Posted October 29, 2010 Hi, Well that seems cool will give it a go! Also you make it sound as if two people running the code at the same time as not a bad thing, but if there orders got mixed it would be! Quote Link to comment Share on other sites More sharing options...
leeh14 Posted November 8, 2010 Author Share Posted November 8, 2010 The session idea seems pretty cool! however will it still work if i have anouther session running! as i have a session running to detect how long a user has been loged in and also which user is loged in? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.