【发布时间】: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);
?>
【问题讨论】:
-
语法错误,也可以考虑使用pdo或者mysqli API
-
$status和$payStatus?另外你很容易受到sql injection attacks -
如果您将 json 数据作为帖子正文而不是表单值发布,那么您需要通过 $json_string = file_get_contents('php://input') 来访问它,例如stackoverflow.com/questions/8893574/php-php-input-vs-post
-
您的费率很低。对 SO 很重要,您必须使用已发布答案左侧、投票下方的勾号来标记已接受的答案。这将提高您的费率。通过访问此链接了解其工作原理:meta.stackoverflow.com/questions/5234/…