pcw Posted March 3, 2009 Share Posted March 3, 2009 Hi, I got the following script for PayPal IPN. I need to it write the transaction details to the SQL database table but it doesnt work. The script below states what works and what doesnt. Does anyone know how to fix this? <?php // Setup class require_once('paypal.class.php'); # New instance of the class $payment = new paypal_class; # PayPal URL $payment->paypal_url = 'https://www.paypal.com/cgi-bin/webscr'; $script_url = 'http://www.move-it-homes.com/sitebuilder/paypal.php'; if (empty($_GET['action'])) $_GET['action'] = 'process'; switch ($_GET['action']) { case 'process': $payment->add_field('item_number', $_POST['item_number']); $payment->add_field('business', '[email protected]'); $payment->add_field('return', $script_url.'?action=success'); $payment->add_field('cancel_return', $script_url.'?action=cancel'); $payment->add_field('notify_url', $script_url.'?action=ipn'); $payment->add_field('item_name', 'Subscription Name'); $payment->add_field('amount', '0.01'); $payment->submit_paypal_post(); break; case 'success': #### THIS DOES NOT PRINT ANYTHING TO THE DATABASE TABLE function insert() { include("data/required.php"); # Database details are in this file mysql_connect('localhost', $dbuser, $dbpass) or die(mysql_error()); mysql_select_db( $db) or die(mysql_error()); $query = "INSERT into payment ( mc_gross, protection_eligibility, address_status, payer_id, tax, address_street, payment_date, payment_status, address_zip, first_name, last_name, address_country_code, address_name, payer_status, address_country, address_city, address_state, quantity, verify_sign, payer_email, pending_reason, transaction_subject, payment_gross ) VALUES ( '$_POST[mc_gross]', '$_POST[protection_eligibility]', '$_POST[address_status]', '$_POST[payer_id]', '$_POST[tax]', '$_POST[address_street]', '$_POST[payment_date]', '$_POST[payment_status]', '$_POST[address_zip], '$_POST[first_name]', '$_POST[last_name]', '$_POST[address_country_code]', '$_POST[address_name]', '$_POST[payer_status]', '$_POST[address_country]', '$_POST[address_city]', '$_POST[address_state]', '$_POST[quantity]', '$_POST[verify_sign]', '$_POST[payer_email]', '$_POST[pending_reason]', '$_POST[transaction_subject]', '$_POST[payment_gross]' ) "; } #### THIS SETS VERIFIED TO YES IN TABLE function verified() { include("data/required.php"); # Database details are in this file mysql_connect('localhost', $dbuser, $dbpass) or die(mysql_error()); mysql_select_db( $db) or die(mysql_error()); $username = mysql_real_escape_string($_POST['username']); mysql_query("UPDATE Users SET verified = 'yes' WHERE username='$username'"); }; insert(); verified(); echo "<html><head><title>Success</title></head><body><h3>Thank you for your order.</h3>"; echo "</body></html>"; break; case 'cancel': echo "<html><head><title>Cancelled</title></head><body><h3>The order was canceled.</h3>"; echo "</body></html>"; break; case 'ipn': if ($payment->validate_ipn()) { $subject = 'Instant Payment Notification - Recieved Payment'; $to = '[email protected]'; $body = "An instant payment notification was successfully recieved\n"; $body .= "from ".$payment->ipn_data['payer_email']." on ".date('m/d/Y'); $body .= " at ".date('g:i A')."\n\nDetails:\n"; foreach ($payment->ipn_data as $key => $value) { $body .= "\n$key: $value"; } mail($to, $subject, $body); } break; } ?> Link to comment https://forums.phpfreaks.com/topic/147769-solved-paypal-ipn-and-mysql-help/ Share on other sites More sharing options...
pcw Posted March 3, 2009 Author Share Posted March 3, 2009 Ok, I managed to get it to write to the mysql db table, but it doesnt write the values from PayPal. This is what I changed: <?php function insert() { include("data/required.php"); # Database details are in this file $link = mysql_connect('localhost', $dbuser, $dbpass); mysql_select_db($db, $link); $query = "INSERT into payment ( ID, mc_gross, protection_eligibility, address_status, payer_id, tax, address_street, payment_date, payment_status, address_zip, first_name, last_name, address_country_code, address_name, payer_status, address_country, address_city, address_state, quantity, verify_sign, payer_email, pending_reason, transaction_subject, payment_gross ) VALUES ( \"ID\", \"$mc_gross\", \"$protection_eligibility\", \"$address_status\", \"$payer_id\", \"$tax\", \"$address_street\", \"$payment_date\", \"$payment_status\", \"$address_zip\", \"$first_name\", \"$last_name\", \"$address_country_code\", \"$address_name\", \"$payer_status\", \"$address_country\", \"$address_city\", \"$address_state\", \"$quantity\", \"$verify_sign\", \"$payer_email\", \"$pending_reason\", \"$transaction_subject\", \"$payment_gross\" ) "; $result = mysql_query($query,$link); } ?> Can anybody tell me what I am doing wrong? Link to comment https://forums.phpfreaks.com/topic/147769-solved-paypal-ipn-and-mysql-help/#findComment-775719 Share on other sites More sharing options...
pcw Posted March 3, 2009 Author Share Posted March 3, 2009 Fixed it. Instead of: \"$mc_gross\" used '$_REQUEST[mc_gross]' Link to comment https://forums.phpfreaks.com/topic/147769-solved-paypal-ipn-and-mysql-help/#findComment-775733 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.