使用PHP进行JSON检索失败。检索到的列只有空值

时间:2016-10-13 11:23:24

标签: php html json rest

我没有检索通过json格式的post命令获得的值,并且始终显示为null。我的PHP代码是

<?php
$con=mysqli_connect ("localhost","crick","password");
if (mysql_error()) {
    echo "Failed to connect to MySQL: " . mysql_error();
}
else
    {

    }
mysqli_select_db($con,'crick');

$response = array();

if (isset($_REQUEST['Team']) && isset($_REQUEST['Opponent']) &&     isset($_REQUEST['Date']) && isset($_REQUEST['Time']) && isset($_REQUEST['Venue'])){
    $Team = $_REQUEST['Team'];
    $Opponent = $_REQUEST['Opponent'];
    $Date = $_REQUEST['Date'];
    $Time = $_REQUEST['Time'];
    $Venue = $_REQUEST['Venue'];    

    $user= mysqli_query($con,"INSERT INTO `match_details`(`Team`, `Opponent`, `Date`, `Venue`) VALUES ('$Team', '$Opponent', '$Date', '$Venue')");
    if ($user) {
        $response["error"] = FALSE;
        $response["user"]["Team"] = $Team;
        $response["user"]["Date"] = $Date;
        $response["user"]["Time"] = $Time;

        $result1 = mysqli_query($con,"SELECT * FROM match_details") or    die(mysqli_connect_errno());
        $no_of_rows1 = mysqli_num_rows($result1);
        if ($no_of_rows1 > 0) {
            $result1 = mysqli_fetch_array($result1);
            $response["user"]["MatchId"] = $result1   ["MatchId"];
        }
        echo json_encode($response);        
    } else {
        $response["error"] = TRUE;
        $response["error_msg"] = "Oops! An error occurred.";

        echo json_encode($response);
    }
} else {
    $response["error"] = TRUE;
    $response["error_msg"] = "Required field(s) is missing";
    echo json_encode($response);
}
?>                          

我的SQL查询是

CREATE TABLE `match_details`
( 
    `MatchId` int(11) NOT NULL,  
    `Team` int(11) NOT NULL,  
    `Opponent` int(11) NOT NULL,  
    `Date` date NOT NULL,  
    `Time` time NOT NULL,  
    `Venue` text NOT NULL,  
    `Won` text NOT NULL,  
    `Runs` int(11) DEFAULT '0',  
    `OpponentRuns` int(11) NOT NULL DEFAULT '0',  
    `4s` int(11) NOT NULL DEFAULT '0',  
    `6s` int(11) NOT NULL DEFAULT '0',  
    `Wickets` int(11) NOT NULL DEFAULT '0',  
    `Opposite4s` int(11) NOT NULL DEFAULT '0',  
    `Opposite6s` int(11) NOT NULL DEFAULT '0',  
    `OppositeWickets` int(11) NOT NULL DEFAULT '0',  
    `Status` int(11) NOT NULL DEFAULT '0',  
    `ManOfMatch` int(11) NOT NULL DEFAULT '0',  

    PRIMARY KEY (`MatchId`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1

我已将输出附加到此

0 个答案:

没有答案