繁体   English   中英

在PHP中处理JSON的后期数据

[英]Handle Post Data of JSON in PHP

我收到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"}

我使用作为JSON帖子数据收到的merchantTransactionId编写了PHP代码来更新我的数据库。 我的数据库不会更新...我的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);
?>

您需要读取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注入攻击和各种恶意攻击开放。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM