Gossamer Forum
Home : General : Perl Programming :

Adding variables to sql data?

Quote Reply
Adding variables to sql data?
Code:
#!/usr/local/bin/perl

# read post from PayPal system and add 'cmd'
read (STDIN, $query, $ENV{'CONTENT_LENGTH'});
$query .= '&cmd=_notify-validate';

# post back to PayPal system to validate
use LWP::UserAgent;
$ua = new LWP::UserAgent;
$req = new HTTP::Request 'POST','https://www.paypal.com/cgi-bin/webscr';
$req->content_type('application/x-www-form-urlencoded');
$req->content($query);
$res = $ua->request($req);

# split posted variables into pairs
@pairs = split(/&/, $query);
$count = 0;
foreach $pair (@pairs) {
($name, $value) = split(/=/, $pair);
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$variable{$name} = $value;
$count++;
}

# assign posted variables to local variables
# note: additional IPN variables also available -- see IPN documentation
$item_name = $variable{'item_name'};
$receiver_email = $variable{'receiver_email'};
$item_number = $variable{'item_number'};
$invoice = $variable{'invoice'};
$payment_status = $variable{'payment_status'};
$payment_gross = $variable{'payment_gross'};
$txn_id = $variable{'txn_id'};
$payer_email = $variable{'payer_email'};

if ($res->is_error) {
# HTTP error
}
elsif ($res->content eq 'VERIFIED') {
# check the payment_status=Completed
# check that txn_id has not been previously processed
# check that receiver_email is an email address in your PayPal account
# process payment
}
elsif ($res->content eq 'INVALID') {
# log for manual investigation
}
else {
# error
}
print "content-type: text/plain\n\nOK\n";


The above code I found from Paypal site.

Now how and where can I add a code, that adds these variables to mysql database:

$item_name = $variable{'item_name'};
$receiver_email = $variable{'receiver_email'};
$item_number = $variable{'item_number'};
$invoice = $variable{'invoice'};
$payment_status = $variable{'payment_status'};
$payment_gross = $variable{'payment_gross'};
$txn_id = $variable{'txn_id'};
$payer_email = $variable{'payer_email'};

MySQL table name :test_table

MySQL column name :test_users

ThanksAngelic

Last edited by:

Suomi: Mar 13, 2002, 8:23 PM
Quote Reply
Re: [Suomi] Adding variables to sql data? In reply to
Hi,

You want to add all that data to just one field- test_users?

Cheers,

Dat

Programming and creating plugins and templates
Blog
Quote Reply
Re: [Suomi] Adding variables to sql data? In reply to
Have you managed to get that Perl code from PayPal actually working? I only managed to get their PHP stuff going. May be an idea to test it before you spend hours working on the script, only to find you get a bad request when making a valid payment ;)

Andy (mod)
andy@ultranerds.co.uk
Want to give me something back for my help? Please see my Amazon Wish List
GLinks ULTRA Package | GLinks ULTRA Package PRO
Links SQL Plugins | Website Design and SEO | UltraNerds | ULTRAGLobals Plugin | Pre-Made Template Sets | FREE GLinks Plugins!