In the file "cargar-obra.page.ts" I have this function:
btnClickAgregarObra(){
const datosObra = {
num_obra: this.num_obra,
nombre_obra: this.nombre_obra,
dir_obra: this.dir_obra,
muni_obra: this.muni_obra,
costo_obra: this.costo_obra,
fecha_ini_obra: this.fecha_ini_obra,
}
this.configService.cargarObra(datosObra).subscribe(res=>console.log(res));
that last line calls this code on "config.service.ts":
public cargarObra(obraData){
console.log(obraData);
return this.http.post('http://localhost/obras.php',obraData,{headers:{'Content-Type':'application/json'}})
}
About that las code, I put the "console.log(obraData)" to see if the json brings the data correctly, and it does.
And the code above calls the las file "obras.php":
$body = file_get_contents("php://input");
$body2 = json_decode($body, true);
$num_obra = $body2['num_obra'];
$nombre_obra = $body2['nombre_obra'];
$dir_obra = $body2['dir_obra'];
$muni_obra = $body2['muni_obra'];
$costo_obra = $body2['costo_obra'];
$fecha_ini_obra = $body2['fecha_ini_obra'];
$inspector_asignado = $body2['inspector_asignado'];
$sql = "INSERT INTO `obra`(`idobra`, `idusuario`, `descripcion`, `direccion`, `localidad`, `fechainicio`, `costo`) VALUES ($num_obra, $inspector_asignado,'$nombre_obra','$dir_obra','$muni_obra','$fecha_ini_obra', $costo_obra)";
$q = mysqli_query($conn, $sql);
die();
What could be happening? Thanks to all help.