I want to insert value to the database
.ts
submitData() {
let datatopost:any = {};
if(this.MySelect1.length >0) {
for(let i=0; i<=this.MySelect1.length; i++) {
datatopost = {"name":this.doc_name[i],"address":this.doc_add[i],"contact":this.doc_cont[i]};
this.post_to_server.push(datatopost);
}
console.log("Final Data...");
this.http.post("http://www.mydomain.com/test/append/includes/classes/multiplefield/insert.php",JSON.stringify(this.post_to_server))
.subscribe(data => {
let temData =data.json()
let response = temData.code;
}, error => {
// Error getting the data
console.log(error);
});
}
}
below my php code .php
<?php include 'connection.php'; if($conn)
{
$json = file_get_contents('php://input');
$obj = json_decode($json,true);
foreach($obj as $key => $value) {
echo $value->name;
$query = 'insert into multiple_filed (send_time,send_location,send_comments) values('.$value->name.','. $value->address.','. $value->contact.')';
mysqli_query($conn,$query); } }
?>
Showing an error like this Trying to get property of non-object
please help me out
Thanks