0

While trying to install IPN with PayPal, the Payement data only get saved in the database.

I have tried everything.

I use PDO with MySQL, And PayPal Sandbox.

This is my save data

the INSERT INTO payements... work, but the DELETE and INSERT INTO sponsored doesn't

$item_number = $_POST['item_number'];
$txn_id = $_POST['txn_id'];
$payment_gross = $_POST['mc_gross'];
$currency_code = $_POST['mc_currency'];
$payment_status = $_POST['payment_status'];
$name = $_POST['name'];
$ip = $_POST['ip'];
$port = $_POST['port'];
$description = $_POST['description'];
$banner = $_POST['banner'];
$owner = $_POST['owner'];

//Check if payment data exists with the same TXN ID.
$prevPayment = $dbh->prepare("SELECT payment_id FROM payments WHERE txn_id = ?");
$prevPayment->execute(array($txn_id));
if($prevPayment->rowCount() > 0){
    exit();
}else{
    //Insert tansaction data into the database
    $sql = $dbh->prepare("DELETE FROM pendingservers WHERE ip = ?");
    $sql->execute(array($ip));
    $query = $dbh->prepare("INSERT INTO sponsored 
                                    (name, ip, port, description, banner, owner) 
                             VALUES (?, ?, ?, ?, ?, ?)");
    $query->execute(array($name, $ip, $port, $description, $banner, $owner));
    $insert = $dbh->prepare("INSERT INTO payments 
                                    (item_number,txn_id,payment_gross,
                                     currency_code,payment_status)
                             VALUES (?, ?, ?, ?, ?)");
    $insert->execute(array($item_number, $txn_id, $payment_gross,
                            $currency_code, $payment_status));
}

The Payement data only get saved (transaction id and such)

RiggsFolly
  • 93,638
  • 21
  • 103
  • 149
  • You are not checking for errors? Check for errors and output the mysql error message and you will be able to fix this yourself [The manual](http://php.net/manual/en/pdo.errorinfo.php) – RiggsFolly Apr 28 '18 at 11:45
  • Its also not clear from your question exactly which part of this code is not working as you expect – RiggsFolly Apr 28 '18 at 11:47
  • I would also say that you should be running this code in a transaction [The manual](http://php.net/manual/en/pdo.begintransaction.php) – RiggsFolly Apr 28 '18 at 11:49
  • @RiggsFolly the INSERT INTO payements... work, but the DELETE and INSERT INTO sponsored doesn't –  Apr 28 '18 at 11:49
  • And I have tried putting it in other file, works as well –  Apr 28 '18 at 11:50
  • Set this in your connection [`$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);`](http://php.net/manual/en/pdo.error-handling.php) Then you should see any errors on the browser – RiggsFolly Apr 28 '18 at 11:54
  • No error appeared, and also, the payement query doesn't get inserted, too. –  Apr 28 '18 at 12:05
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/169989/discussion-between-houssem-ben-taher-and-riggsfolly). –  Apr 28 '18 at 12:16
  • Did you look in the Error log for useful info – RiggsFolly Apr 28 '18 at 12:18
  • Add [error reporting](http://stackoverflow.com/questions/845021/how-to-get-useful-error-messages-in-php/845025#845025) to the top of your file(s) _while testing_ right after your opening PHP tag for example ` – RiggsFolly Apr 28 '18 at 12:18
  • Hmm, how to enable Error log? –  Apr 28 '18 at 12:22
  • Add that code in previous comment to the top of a script you are debugging – RiggsFolly Apr 28 '18 at 12:23
  • No error appeared –  Apr 28 '18 at 12:27

0 Answers0