用户完成了一项调查,完成后,它通过ajax发送了一个包含对PHP的问答的json。然后,PHP解码json并使用准备好的语句发送到MySQL数据库,但是数据库并未填充。
我没有收到任何可能导致此问题的错误。
谢谢!
<?php
$json = (file_get_contents("php://input"));
$obj = json_decode($json,true);
header("Content-Type: application/json; charset=UTF-8")
$servername = "localhost";
$username = "root";
$password = "password";
$dbname = "arc";
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
$Age = .$obj->q1.;
$Race_Ethnicity = .$obj->q2.;
$International_Student = .$obj->q3.;
$Sexual_Orientation = .$obj->q4.;
$Year_Of_School = .$obj->q5.;
$Participations = .$obj->q6.;
$Living_Situation = .$obj->q7.;
$Question1_SH = .$obj->q7.;
$Question2_SH = .$obj->q7.;
$Question3_SH = .$obj->q7.;
$Question4_SH = .$obj->q7.;
$Question5_SH = .$obj->q7.;
$Question6_SH = .$obj->q7.;
$Question7_SH = .$obj->q7.;
$Question8_SH = .$obj->q7.;
$Question9_SH = .$obj->q7.;
$Question10_SH = .$obj->q7.;
$Question11_SH = .$obj->q7.;
$Question12_SH = .$obj->q7.;
$Question13_SH = .$obj->q7.;
$Question14_SH = .$obj->q7.;
$Question15_SH = .$obj->q7.;
$Question16_SH = .$obj->q7.;
$F_Up_Question1_SH = .$obj->q7.;
$F_Up_Question2_SH = .$obj->q7.;
$F_Up_Question3_SH = .$obj->q7.;
$F_Up_Question4_SH = .$obj->q7.;
$F_Up_Question5_SH = .$obj->q7.;
$sql = "INSERT INTO results ( Age, Race_Ethnicity, International_Student, Sexual_Orientation,
Year_Of_School, Participations, Living_Situation, Question1_SH, Question2_SH, Question3_SH,
Question4_SH, Question5_SH, Question6_SH, Question7_SH, Question8_SH, Question9_SH,
Question10_SH, Question11_SH, Question12_SH, Question13_SH, Question14_SH, Question15_SH, Question16_SH,
F_Up_Question1_SH, F_Up_Question2_SH, F_Up_Question3_SH, F_Up_Question4_SH, F_Up_Question5_SH)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?,
) ;"
$stmt = mysqli_stmt_init($conn);
if (!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL Error";
} else {
//bind paramaters to the placeholders
mysqli_stmt_bind_param($stmt, "ssssssssssssssssssssssssssss", $Age, $Race_Ethnicity, $International_Student, $Sexual_Orientation,
$Year_Of_School, $Participations, $Living_Situation, $Question1_SH, $Question2_SH, $Question3_SH,
$Question4_SH, $Question5_SH, $Question6_SH, $Question7_SH, $Question8_SH, $Question9_SH,
$Question10_SH, $Question11_SH, $Question12_SH, $Question13_SH, $Question14_SH, $Question15_SH, $Question16_SH,
$F_Up_Question1_SH, $F_Up_Question2_SH, $F_Up_Question3_SH, $F_Up_Question4_SH, $F_Up_Question5_SH
);
mysqli_stmt_execute($stmt);
}
?>
CREATE TABLE `results` (
`Age` varchar(45) DEFAULT NULL,
`Race_Ethnicity` varchar(45) DEFAULT NULL,
`International_Student` varchar(45) DEFAULT NULL,
`Sexual_Orientation` varchar(45) DEFAULT NULL,
`Year_Of_School` varchar(45) DEFAULT NULL,
`Participations` varchar(45) DEFAULT NULL,
`Living_Situation` varchar(45) DEFAULT NULL,
`Question1_SH` varchar(45) DEFAULT NULL,
`Question2_SH` varchar(45) DEFAULT NULL,
`Question3_SH` varchar(45) DEFAULT NULL,
`Question4_SH` varchar(45) DEFAULT NULL,
`Question5_SH` varchar(45) DEFAULT NULL,
`Question6_SH` varchar(45) DEFAULT NULL,
`Question7_SH` varchar(45) DEFAULT NULL,
`Question8_SH` varchar(45) DEFAULT NULL,
`Question9_SH` varchar(45) DEFAULT NULL,
`Question10_SH` varchar(45) DEFAULT NULL,
`Question11_SH` varchar(45) DEFAULT NULL,
`Question12_SH` varchar(45) DEFAULT NULL,
`Question13_SH` varchar(45) DEFAULT NULL,
`Question14_SH` varchar(45) DEFAULT NULL,
`Question15_SH` varchar(45) DEFAULT NULL,
`Question16_SH` varchar(45) DEFAULT NULL,
`F_Up_Question1_SH` varchar(45) DEFAULT NULL,
`F_Up_Question2_SH` varchar(45) DEFAULT NULL,
`F_Up_Question3_SH` varchar(45) DEFAULT NULL,
`F_Up_Question4_SH` varchar(45) DEFAULT NULL,
`F_Up_Question5_SH` varchar(45) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
此处是带有最新代码的实时调查链接 http://highdemanddesigns.com/arc3s/survey