我试图从我的register.component.ts页面发送http post请求到register_insert.php页面。但是我得到了HttpErrorResponse错误。我哪里做错了?请帮助解答一下谢谢
register.component.ts
insertData() {
this.httpClient.post(
"http://localhost/register_insert.php",
{
'fullname':this.fullname,
'email':this.email,
'role':this.role,
'typee':this.typee,
'password':this.password,
},
).subscribe((data) => {
alert("inserted");
console.log(data);
this.fullname = null;
this.email = null;
this.role = null;
this.typee = null;
this.password = null;
},
(err)=>{
console.log(err);
});
}
register_insert.php
<?php
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Methods: GET, POST, PUT, PATCH, POST, DELETE, OPTIONS");
header('Access-Control-Max-Age: 86400');
header("Access-Control-Expose-Headers: Content-Length, X-JSON");
header("Access-Control-Allow-Headers: *");
include 'dbcon.php';
$data = json_decode(file_get_contents("php://input"),true);
if(count($data) > 0 ) {
$fullname = mysqli_real_escape_string($connect,$data['fullname']);
$email = mysqli_real_escape_string($connect, $data['email']);
$role = mysqli_real_escape_string($connect,$data['role']);
$type = mysqli_real_escape_string($connect, $data['typee']);
$password = mysqli_real_escape_string($connect,$data['password']);
$insert = "INSERT INTO tbl_user values ('','$fullname','$email','$role','$type','$password')";
if(mysqli_query($connect,$insert)){
echo "Data inserted";
} else {
echo "Data not inserted" . mysqli_error($connect);
}
}
?>