Reputation: 388
Im using angular httpclient and php in back-end for handling data in my angular application. But im getting following error when im trying to save data.
Error Im Getting
Im using following database.service.ts angular service to connect whit database and pass data
insertFabricData(value){
return this._http.post("http://localhost/jeleena-api/fabric.php",value).pipe(map(res => {
console.log(res);
}));
}
And Im Using fabric.component.tsto call database.service.ts file from front end
saveFormData(){
this._databaseService.insertFabricData(this.fabric).subscribe(msg => {
console.log('yes');
console.log(msg);
});
}
Following is my php code which is running on my localhost fabric.php
<?php
//Get Data From Front End
$data = json_decode(file_get_contents("php://input"));
//Create Database Connection
include "db-connection.php";
//SQL Statements
$sql = "INSERT INTO fabric_details (bill_id,fabric_swetch,fabric_width,unit,fabric_category,colour,
total,temp_meter,temp_price,actual_meter,actual_price,finish) VALUES
('$data->bill_number','$data->fabric_swetch','$data->fabric_width','$data->unit',
'$data->fabric_category','$data->colour','$data->total','$data->temp_meter','$data->temp_price','$data->actual_meter',
'$data->actual_price','$data->finish')";
//Check Null Values
if($data){
//Run The Query Only Name Exitsqty
$qry = $conn->query($sql);
}
//Close Database Connection
$conn->close();
?>
Upvotes: 0
Views: 577
Reputation: 346
The problem is because, the http post try to parse result from api ,
but you not return anything from fabric.php , i dont know what exactly return result in php , if we doesn't have return value.
but so far i know, when http post try to parse, he get the invalid format, that's why you get error.
Upvotes: 1