I’m trying to insert dynamic field value into DB
below my ts
``
submitData() {
let datatopost:any = {};
if(this.MySelect1.length>0 ||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);
}
}
this.http.post("http://www.mydomain.com/multiplefield/insert.php",
JSON.stringify(this.post_to_server)).subscribe(data => {
let server = data.json();
let respose = server.status;
alert(respose)
});
}
``
.php
``
<?php
$con=mysqli_connect("localhost","username","pass","dbname");
$postdata = file_get_contents("php://input");
$obj = json_decode($postdata,TRUE);
foreach($obj as $key)
{
//$query = "insert into test (name,address,doc_contact) values (".$key['name'].",".$key['address'].",".$key['contact'].")";
$query = "insert into test (name,address,doc_contact) values ('".$key['name']."','".$key['address']."','".$key['contact']."')";
$result = mysqli_query($con,$query); //execute $query with mysqli_query
}
$result=1; /*default, if $result = mysqli_query($conn,$query) executed successfully you will $result =1 */
if($result > 0) {
$reply['status']='1';
$reply['message']='Data Inserted successfully';
} else {
$reply['status']='0';
$reply['message']='Failed...';
}
echo json_encode($reply);
?>
``
not thing show in
this alert
alert(respose)
how can i fiexed that
please help me out