【问题标题】:Handle Post Data of JSON in PHP在 PHP 中处理 JSON 的 Post 数据
【发布时间】:2015-09-15 00:57:06
【问题描述】:

我收到 JSON 发布数据 ....

{"split_info":"17076370","customerName":"Lahoti","status":"failed","error_Message":"fail.","paymentId":"17076370","productInfo":"productInfo","customerEmail":"cxxxx.xx@gmail.com","customerPhone":"999999999","merchantTransactionId":"BR121","amount":"19.0","notificationId":"443"}

我已经编写了 PHP 代码来使用作为 JSON 发布数据接收的 MercerTransactionId 来更新我的数据库。 我的数据库不会更新... 我的php代码如下 请帮忙。。

<?php
include("dbconnection.php");
if(isset($_POST))
{
$json_a = json_decode($_POST, true);
 $Id=$json_a['merchantTransactionId'];
 $status="payUMoney";
 mysql_query("UPDATE std SET status= '".$payStatus."' WHERE Id='".$Id."'", $db);
?>

【问题讨论】:

标签: php mysql json


【解决方案1】:

您需要读取 HTTP 请求正文目录,因为 $_POST 仅提供表单数据,从它的声音来看,您正在尝试接收 json/应用程序请求?

<?php
include("dbconnection.php");

$json_string = file_get_contents('php://input');

if($json_string !== null)
{
 $json_a = json_decode($json_string, true);
 $Id=$json_a['merchantTransactionId'];
 $status="payUMoney";
 mysql_query("UPDATE std SET status= '".$payStatus."' WHERE Id='".$Id."'", $db);
}
?>

请永远不要以这种方式生成 SQL 语句,它们非常不安全,并且会让您容易受到 SQL 注入攻击和各种讨厌的攻击。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-17
    • 1970-01-01
    • 1970-01-01
    • 2010-09-20
    • 1970-01-01
    • 1970-01-01
    • 2023-03-19
    • 2013-06-12
    相关资源
    最近更新 更多