Jump to content

PHP Paypal PDT and Query


ncos

Recommended Posts

Hi All,

 

Would anybody be able to help me? I've got a Paypal PDT script which works fine (im using the item_number variable as my ID) but when the information is passed back i've got a SQL query which selects the record based on the ID in order to start producing PDFs etc. The problem is I keep getting "Query Error!" and have tried many variations on the query and even echo'd the $ID variable on the line before the Select Query which even shows the current ID and is correct. I know this is probably basic but any help would be greatly appreciated. (Please see script attached)

 

Regards,

 

Neil

 

<?php

 

 

//================================================================================

//========================PAYPAL PDT==============================================

//================================================================================

 

##    PayPal base PDT script to capture full NVP data pairs.    ##

## Also captures initial GET/POST data captured prior to full PDT ##

 

#error_reporting(E_ALL);

error_reporting(0);

 

# add your own sig hash obtained from PDT profile

$auth_token = "------";

 

// read the post from PayPal system and add 'cmd'

$req = 'cmd=_notify-synch';

$tx_token = $_GET['tx'];

$req .= "&tx=$tx_token&at=$auth_token";

 

// 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";

 

// If possible, securely post back to paypal using HTTPS

// Your PHP server will need to be SSL enabled

#$fp = fsockopen ('www.paypal.com', 80, $errno, $errstr, 30);

#$fp = fsockopen ('www.sandbox.paypal.com', 80, $errno, $errstr, 30);

#$fp = fsockopen ('ssl://www.paypal.com', 443, $errno, $errstr, 30);

$fp = @fsockopen ('ssl://www.sandbox.paypal.com', 443, $errno, $errstr, 30);

 

if (!$fp) {

// HTTP ERROR

echo "NO HTTP! [$errno], [$errstr]<br>";

} else {

fputs ($fp, $header . $req);

// read the body data

$res = '';

$headerdone = false;

while (!feof($fp)) {

  $line = fgets ($fp, 1024);

  if (strcmp($line, "\r\n") == 0) {

  // read the header

  $headerdone = true;

  }

  else if ($headerdone){

  // header has been read. now read the contents

  $res .= $line;

  }

}

 

$keyarray = array();

// parse the data

$lines = explode("\n", $res);

if (strcmp ($lines[0], "SUCCESS") == 0) {

  for ($i=1; $i<count($lines);$i++){

  list($key,$val) = explode("=", $lines[$i]);

  $key=urldecode($key);

  $val=urldecode($val);

  if($key){$keyarray[$key] = $val;}

  }

 

//  if($_SERVER['REQUEST_METHOD']=='GET'){

//  foreach($_GET as $ky => $val){

//    echo urldecode($ky).' = '.urldecode($val)."<br>\n";

//  }

//  }

//  elseif($_SERVER['REQUEST_METHOD']=='POST'){

//  foreach($_POST as $ky => $val){

//    echo urldecode($ky).' = '.urldecode($val)."<br>\n";

//  }

//  }

 

  // 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

  $firstname = $keyarray['first_name'];

  $lastname = $keyarray['last_name'];

  $amount = $keyarray['payment_gross'];

  $ID = $keyarray['item_number'];

 

  echo ("<p><h3>Thank you for your purchase!</h3></p>");

  echo ("<b>Payment Details</b><br>");

  echo ("Name: $firstname $lastname<br>");

  echo ("Amount: $amount<br>");

  echo ("ID: $ID<br>");

 

  //foreach($keyarray as $name=>$value){

  //echo "[ $name ] $value<br>\n";

  //}

 

}

else if (strcmp ($lines[0], "FAIL") == 0) {

  // log for manual investigation

  $rslt-"$errno, $errstr; Mission FAILED. Sorry.";

  echo "$rslt<br>";

  #draw();

}

 

}

 

if($fp){fclose($fp);}

 

#echo "Your transaction has been completed, and a receipt for your

# purchase has been emailed to you.<br>";

#echo "You may log into your account at

# <a href='https://www.paypal.com'>www.paypal.com</a> to

# view details of this transaction.<br>";

 

 

//================================================================================

//========================SELECT RECORD===========================================

//================================================================================

 

 

$usr = "----";

$pwd = "----";

$db = "----";

$host = "localhost";

 

$cid = mysql_connect($host,$usr,$pwd) or die("Couldn't connect to db!");

 

$rs = mysql_query("SELECT * from er_hip WHERE ID = $ID") or die("Query error!");

 

echo "<hr>\n";

    while (list($ID, $Title, $Fname, $SName, $address1, $address2, $address3, $address4, $address5, $email, $date, $time) = mysql_fetch_row($rs)) {

echo "Thank you, your Reference Number is $ID";

 

?>

Link to comment
https://forums.phpfreaks.com/topic/114830-php-paypal-pdt-and-query/
Share on other sites

ncos...

you have not selected any database....

 

 

your code:

 

$usr = "----";
$pwd = "----";
$db = "----";
$host = "localhost";

$cid = mysql_connect($host,$usr,$pwd) or die("Couldn't connect to db!");

$rs = mysql_query("SELECT * from er_hip WHERE ID = $ID") or die("Query error!");

echo "\n";
    while (list($ID, $Title, $Fname, $SName, $address1, $address2, $address3, $address4, $address5, $email, $date, $time) = mysql_fetch_row($rs)) {
echo "Thank you, your Reference Number is $ID";

?>
[code]


it should be like this:

your code:

[code]
$usr = "----";
$pwd = "----";
$db = "----";
$host = "localhost";

$cid = mysql_connect($host,$usr,$pwd) or die("Couldn't connect to db!");

mysql_select_db($db, $cid);

$rs = mysql_query("SELECT * from er_hip WHERE ID = $ID") or die("Query error!");

echo "\n";
    while (list($ID, $Title, $Fname, $SName, $address1, $address2, $address3, $address4, $address5, $email, $date, $time) = mysql_fetch_row($rs)) {
echo "Thank you, your Reference Number is $ID";

?>
[code]

[/code][/code][/code]

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.