我在从iForm解析一些POSTed JSON时遇到了一些问题。从下面的代码中,我得到一个MySQL错误"列数与第1行和第34行的值计数不匹配。
我已经查看过相关问题,但无法解决此问题 - 似乎$ data [test]返回一个空字符串。 POSTed JSON是有效的,如果我保存本地副本并从中读取,则代码可以正常工作。
Dim msSQLComm As SqlCommand = New SqlCommand("csp_LoginAuthentication", sqlConnct.MSSQLConn )
示例JSON POST:
<?php
ini_set("allow_url_fopen", true);
echo('hi');
$data = json_decode(file_get_contents('php://input'), TRUE);
$text = print_r($data,true);
$submit = $data[test];
$servername = "213.171.XXX.75";
$username = "xxxxxxx";
$password = "xxxxxxxxxxxxx";
$dbname = "xxxxxxxxx";
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "INSERT INTO testing (col1) VALUES ($data[test])";
if (mysqli_query($conn, $sql)) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($conn);
}
mysqli_close($conn);
?>
答案 0 :(得分:2)
根据您的数据,您需要更深入一级:
$data['record']['test']