为什么我的陈述总是假的?if(isset($ _ GET ['action'])&& $ _GET ['action'] =='IPN_Handler') [英] Why is my statement always false? if (isset($_GET['action']) && $_GET['action']=='IPN_Handler')

查看:48
本文介绍了为什么我的陈述总是假的?if(isset($ _ GET ['action'])&& $ _GET ['action'] =='IPN_Handler')的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为PayPal编写了IPN侦听器,当我第一次这样做时,一切都很好.我不知道为什么,它停止工作了.我的即时付款通知设置为: https://domainname/webpage/?action = IPN_Handler

I wrote an IPN listener for PayPal and when I first did it everything worked fine. I am not sure why, it stopped working. My Instant Payment Notification is set to: https://domainname/webpage/?action=IPN_Handler

网站付款网址的自动返回为: https://域名/网页

Auto return for website payments url is: https://domainname/webpage

我的监听器代码是:

if (isset($_GET['action']) && $_GET['action']=='IPN_Handler') {
    echo "Thank you for your payment";
    $amt = $_GET['amt'];
    $txn_id = $_GET['tx'];
    $st = $_GET['st'];
    $msg = $_GET['item_name'];
    $date= date("Y-m-d");
   }

代码返回后,页面将在位置区域中显示以下内容:链接

Once the code returns the page has this in the location area: Link

我在if语句上添加了 var_dum p,它返回了 bool(false).

I added a var_dump on the if statement and it returns bool(false).

我的代码在做什么错?

推荐答案

感谢您的来信,让我向您解释如何在付款过程中高效升级准备对帐单.我没有您的所有数据,因此我将按照您所显示的内容进行处理.

Thanks for hearing me, Let me explain you how to upgrade prepare statement espacily in a payment process. I dont have all your data so I will do it with what you showed in question.

这是一个简单的准备声明,希望对您有所帮助.

Here is a simple prepare statement, hope it will help you.

$ conn 是数据库连接字段,将其更改为您的

$conn is db connection field change it to yours

if (isset($_POST['action']) && $_POST['action']=='IPN_Handler') { 
// we get all params from html form I use post method always if dont need to get a url paratemer
    $amt = htmlspecialchars($_POST['amt']);
    $txn_id = htmlspecialchars($_POST['tx']);
    $st = htmlspecialchars($_POST['st']);
    $msg = htmlspecialchars($_POST['item_name']);
    $date= date("Y-m-d");

//Here we need to validate form inputs
    if(empty($amt) || empty($txn_id) || empty($st) || empty($msg)) { 
        echo "Field all required";
    }else{

        $stmt = $conn->prepare("INSERT INTO Your_table_name (amt, tx, st, item_name, date) VALUES (?, ?, ?, ?, ?)");
        $stmt->bind_param("sssss", $amt, $txn_id, $st, $msg, $date);
         // we used bind_param so now we need to execute 
        if($stmt->execute()){
            echo "New records created successfully";
            header('Location: yourpage.php');
            exit();
        }else{
            echo "Failed to insert new records in database.";
        }

        // Free yourconnection
        $stmt->free_result();
    }
}

更新:经过测试,可以在这里处理html表单:

UPDATE : Tested working on my case here is html form :

<form action="page.php" method="POST">
	<input type="text" name="amt" placeholder="dsdsd">
	<input type="text" name="tx" placeholder="sdsd">
	<input type="text" name="st" placeholder="dsdsd">
	<input type="text" name="item_name" placeholder="sdsd">
	<input type="text" name="date" placeholder="dsdsd">
	<input type="hidden" name="action" value="IPN_Handler" />
	<input type="submit" name="LoginBtn" placeholder="signup">
</form>

有关更多说明,请参见此处 https://www.w3schools.com/php/php_mysql_prepared_statements.asp

For more explanition see here https://www.w3schools.com/php/php_mysql_prepared_statements.asp

在这里,我修改了您的代码:

Here is where I modified your code:

if (isset($_GET['action']) AND $_GET['action']=='IPN_Handler') {

//Here we need to validate form inputs
  $amt = mysqli_real_escape_string($link, $_GET['amt']);
  $txn_id = mysqli_real_escape_string($link, $_GET['tx']);
  $st = mysqli_real_escape_string($link, $_GET['st']);
  $msg = mysqli_real_escape_string($link, $_GET['item_name']);
  $date= date("Y-m-d");

    $sql = "UPDATE wp_ready2_play SET amount=?, payment_id=?, payment_status=?, message=?,  payment_dte=? WHERE id =?";
    $stmt = mysqli_stmt_init($link);
        if (!mysqli_stmt_prepare($stmt, $sql)) {
        echo "SQL error";
    } else {
        mysqli_stmt_bind_param($stmt, "ssssss", $amt, $txn_id, $st, $msg, $date, $data);
        mysqli_stmt_execute($stmt);
        echo "Thank you for your payment";
        echo "Transaction has been made successfully.";
    }   
    // Free yourconnection
    mysqli_free_result($stmt);

}

这篇关于为什么我的陈述总是假的?if(isset($ _ GET ['action'])&amp;&amp; $ _GET ['action'] =='IPN_Handler')的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆