php - I can't seem to find why this IPN code is not updating database -
i ran code without errors database not updating. receiving variable data paypal correctly. verify post data added 2 lines @ beginning of script write variables text file. server uses php 5.4. hope guys can find problem.
<?php /* checking post variables & writing text file */ $posted_data = print_r($_post,true); file_put_contents('ipn_data.txt',$posted_data); /* database config here */ /* connect database */ $conn = new mysqli($db_host, $db_user, $db_pass, $db_database); if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } //read post paypal system , add 'cmd' $req = 'cmd=_notify-validate'; foreach ($_post $key => $value) { $value = urlencode(stripslashes($value)); $req .= "&$key=$value"; } //post paypal system validate $header = "post /cgi-bin/webscr http/1.1\r\n"; $header .= "content-type: application/x-www-form-urlencoded\r\n"; $header .= "host: www.sandbox.paypal.com\r\n"; $header .= "connection: close\r\n"; $header .= "content-length: " . strlen($req) . "\r\n\r\n"; $fp = fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30); // $item = $_post['item_name']; $transaction_id = $_post['txn_id']; $payeremail = $_post['payer_email']; //error connecting paypal if (!$fp) { // } //successful connection if ($fp) { fputs ($fp, $header . $req); while (!feof($fp)) { $res = fgets ($fp, 1024); $res = trim($res); //new & important if (strcmp($res, "verified") == 0) { //insert order database if (strcmp ($payment_status, "completed") == 0) { /* update database */ if($item == 'learn html'){ $sql = "insert dc_html (transaction_id,email_id) values ( '$transaction_id','$payeremail')"; $conn->close(); break; } if($item == 'learn css') { $sql = "insert dc_css (transaction_id,email_id) values ( '$transaction_id','$payeremail')"; $conn->close(); break; } } } if (strcmp ($res, "invalid") == 0) { //insert db in table bad payments process later } } fclose($fp); } ?>
you seem assign query $sql variable not appear in code call $conn->query($sql).
if not execute query how inserted database?
also adding logging might debug more easily.
like send email or write error file if
- postback fails
- db connection fails
- db query execution fails
hope helps.
Comments
Post a Comment