0

i have a little problem and i have no clue on how to solve it, i´ve tried everything i could and i have no idea where the problem is, the thing is that after the ipn listener insert the transaction data into the ipn_data_tbl, i want to update the record with the same value as $custom, but is not working, is the only thing i need, everything else but this is working as expected, this is my code:

  $tokens = explode("\r\n\r\n", trim($res));
$res = trim(end($tokens));
if (strcmp($res, "VERIFIED") == 0 || strcasecmp($res, "VERIFIED") == 0) {

    //Payment data
    $item_name = $_POST['item_name'];
    $txn_id = $_POST['txn_id'];
    $payment_gross = $_POST['mc_gross'];
    $currency_code = $_POST['mc_currency'];
    $payment_status = $_POST['payment_status'];
    $create_date = date('Y-m-d H:i:s');
    $payment_date = date('Y-m-d H:i:s');
    $payer_email = $_POST['payer_email'];
    $txn_type = $_POST['txn_type'];
    $custom = $_POST['custom'];

//Check if payment data exists with the same TXN ID.
$prevPayment = $con->query("SELECT UID FROM ipn_data_tbl WHERE txn_id = '".$txn_id."'");
if($prevPayment->num_rows > 0){
    exit();
}else{
    //Insert tansaction data into the database
    $insert = $con->query("INSERT INTO ipn_data_tbl(item_name,txn_id,amount,currency,payment_status,create_date,payment_date,payer_email,txn_type,UID) VALUES('".$item_name."','".$txn_id."','".$payment_gross."','".$currency_code."','".$payment_status."','".$create_date."', '".$payment_date."','".$payer_email."','".$txn_type."','".$custom."')");

}

if ($con->query($insert) === TRUE) {

    echo $update = $con->query("UPDATE `transportation` SET `paypal_status`='$payment_status' WHERE `id`='$custom'");
}
else {
    $delete = $con->query("DELETE FROM transportation WHERE txn_id = '".$txn_id."'");
}

}
  • Where in your code do you check for PHP or MySQL errors? – Jocelyn Feb 11 '17 at 15:49
  • Hoo i´m sorry, this is just the bottom of my code, i got the connection file and everything else on the begining (on another file using include) – Fernando Dlp Feb 11 '17 at 15:56
  • `$server = "localhost"; $username = "myuser"; $password = "mypassword"; $database = "thedatabasename"; $con = new mysqli($server,$username,$password,$database); if (!$con){ die('Could not connect: ' . mysqli_connect_error($con)); }` – Fernando Dlp Feb 11 '17 at 15:58
  • Possible duplicate of [How to get mysqli error in different environments?](https://stackoverflow.com/questions/22662488/how-to-get-mysqli-error-in-different-environments) – Funk Forty Niner Mar 10 '18 at 00:57

1 Answers1

0

I'm sorry, the only thing i had to change was this:

    if ($con->query($insert) === TRUE) {

    echo $update = $con->query("UPDATE `transportation` SET `paypal_status`='$payment_status' WHERE `id`='$custom'");
}
else {
    $delete = $con->query("DELETE FROM transportation WHERE txn_id = '".$txn_id."'");
}

to this

if ($insert) === TRUE) {

    echo $update = $con->query("UPDATE `transportation` SET `paypal_status`='$payment_status' WHERE `id`='$custom'");
}
else {
    $delete = $con->query("DELETE FROM transportation WHERE txn_id = '".$txn_id."'");
}