Php vue应用程序的axios.post()调用未插入到db
我正在使用vue应用程序中对axios.post()的调用来连接我的php文件,该文件将在sql数据库中插入一条记录。 以下是我从vue应用程序打给axios的电话:Php vue应用程序的axios.post()调用未插入到db,php,vuejs2,axios,Php,Vuejs2,Axios,我正在使用vue应用程序中对axios.post()的调用来连接我的php文件,该文件将在sql数据库中插入一条记录。 以下是我从vue应用程序打给axios的电话: this.axios.post('http://localhost/DbConnection/submitSession.php' , { params: { sessionDate: this.date,
this.axios.post('http://localhost/DbConnection/submitSession.php' , {
params: {
sessionDate: this.date,
start_time: this.start_time,
end_time: this.end_time
},
headers: {
"Access-Control-Allow-Origin": "*",
"Access-Control-Allow-Methods": "GET, POST, PATCH, PUT, DELETE, OPTIONS",
"Access-Control-Allow-Headers": "Origin, Content-Type, X-Auth-Token"
}
})
.then((response) => {this.submitSessionSuccess(response);})
.catch((error )=> {this.submitSessionFailure(error);});
我知道我得到的是一个响应,而不是一个错误,因为它将进入然后
,调用submitSessionSuccess
并传递响应
。但是,会话没有插入数据库,我无法在控制台中解析响应。
响应
返回[Object][Object]
,响应。数据
不返回任何内容。
我还在下面发布我的php代码
这里给出的答案是:没有说明如何提取发送给php的每个字段,以便它可以将它们插入数据库。这里发布的答案:没有回答这个问题,主要是因为我没有将post请求数据作为JSON发送
我非常感谢大家对我的帮助
submitSession.php:
if (isset($_POST['sessionDate'], $_POST['start_time'], $_POST['end_time']))
{
require_once("connectToDB.php");
$date = $_POST['sessionDate'];
$startTime = $_POST['start_time'];
$endTime = $_POST['end_time'];
$query = "insert into session (sessionDate, startTime, endTime) VALUES (?, ?,?)";
$stmt = mysqli_prepare($con, $query);
mysqli_stmt_bind_param($stmt, "sss", $date,$startTime,$endTime);
mysqli_stmt_execute($stmt);
$affected_rows = mysqli_stmt_affected_rows($stmt);
$response=false;
if($affected_rows == 1){
$response = true;
}
else {
$response= false;
}
echo json_encode($response);
mysqli_stmt_close($stmt);
mysqli_close($con);
}
die();
sidepoint,您发送的响应标题,它们不是请求的标题。@LawrenceCherone-不确定您的评论是什么意思,您能解释一下吗?另外,我看了这些答案,他们没有回答我的问题。如果你能看一下并给出答案,我将不胜感激。