close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

paypal update db Help Pls

Thread began 3/22/2012 9:59 am by jamie424562 | Last modified 3/24/2012 4:28 am by jamie424562 | 2385 views | 5 replies |

jamie424562

paypal update db Help Pls

This may be a silly question but am stuck as one can be, have read a few forums and am getting no where.
Have added a paypal button for subscription, and want it to update the user db (groupID) when successfull, anyone have some script that can help with this please.
Or maybe another link which makes this a little more clear.
Have tried the net tuts guide and a few others so far.

Thanks in advance.

Sign in to reply to this post

jamie424562

have enabled ipn on paypal, copied ipn script and added the following:


<?php
mysql_connect("localhost", "root", "root") or die(mysql_error());
mysql_select_db("users") or die(mysql_error());

// read the post from PayPal system and add 'cmd'
$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

// 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.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$item_name = $_POST['item_name'];
$item_number = $_POST['item_number'];
$payment_status = $_POST['payment_status'];
$payment_amount = $_POST['mc_gross'];
$payment_currency = $_POST['mc_currency'];
$receiver_email = $_POST['receiver_email'];
$payer_email = $_POST['payer_email'];

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

// check the payment_status is Completed
// check that txn_id has not been previously processed
// check that receiver_email is your Primary PayPal email
// check that payment_amount/payment_currency are correct
// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>

Got this far, just not far enough.......

Sign in to reply to this post

Jason ByrnesWebAssist

the email address for the customer is coming through in a form element payer_email

$payer_email = $_POST['payer_email'];


you can add an update record behavior to update the users table, set the key column to the email column and use the following code for the value:

php:
<?php echo((isset($_POST["payer_email"]))?$_POST["payer_email"]:""?>
Sign in to reply to this post

jamie424562

Thanks for replying Jason
Like I said am a bit lost, actualy feel realy stupid here.....

so that I get this right...

Have edited the ipn form to the following:

<?php
mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("users") or die(mysql_error());

$req = 'cmd=_notify-validate';

foreach ($_POST as $key => $value) {
$value = urlencode(stripslashes($value));
$req .= "&$key=$value";
}

$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.paypal.com', 443, $errno, $errstr, 30);

// assign posted variables to local variables
$payer_email = $_POST['payer_email'];

if (!$fp) {
// HTTP ERROR
} else {
fputs ($fp, $header . $req);
while (!feof($fp)) {
$res = fgets ($fp, 1024);
if (strcmp ($res, "VERIFIED") == 0) {

mysql_query("UPDATE users SET groupID = '2' WHERE $_SESSION = ['SecurityAssist_UserID']");

// process payment
}
else if (strcmp ($res, "INVALID") == 0) {
// log for manual investigation
}
}
fclose ($fp);
}
?>

Am guessing this is right for the insert, but then i get lost when "set the key column to the email column " and then use the code you included.....
Maybe its late and my brain is fried already, but still what's the change of finishing it for us so i can get this done, be super grateful am sure its a quick fix for urself also am also sure will understand it alot better if actually complete.
Thanks again

Sign in to reply to this post

Jason ByrnesWebAssist

your update code is not correct:

mysql_query("UPDATE users SET groupID = '2' WHERE $_SESSION = ['SecurityAssist_UserID']");


you need to either update on the update based on the UserID column and the value in the SecurityAssist_UserID session:


mysql_query("UPDATE users SET groupID = '2' WHERE UserID = $_SESSION['SecurityAssist_UserID']");


or the email column being equal to the $payer_email value, assuming the name of the email column is UserEmail::


mysql_query("UPDATE users SET groupID = '2' WHERE UserEmail = '$payer_email'");

Sign in to reply to this post

jamie424562

Thanks Jason, thats a lot clearer now!

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...