Good day, I have a problem, I have my file JSON
by xampp, and effectively this code extracts the data I need in JSON
.
In the part of PHP
, if you receive files JSON
and insert them into the database very well, but when working with angular, I send you the data that I collect in HTML
, which effectively combierte in JSON
but does not pass these files JSON
to PHP
for you to insert them into the database.
The variable this.url=" link "
The link of the index is the url + Datos_Sencibilizacion
and show that if you find the JSON
that I want to see in angular or that I also want to import it to PHP
to insert it
getSencibilizacion(): Observable < SencibilizacionModel[] > {
return this._http
.get(this.url + 'Datos_Sencibilizacion')
.map((res: Response) => res.json())
.catch((error: any) => Observable.throw(error.json().error))
}
//SECCION POST
postSencibilizacion(Dato_sencibilizacion: SencibilizacionModel) {
let json = JSON.stringify(Dato_sencibilizacion);
let params = 'json=' + json;
let headers = new Headers();
headers.append('Content-Type', 'application/x-www-form-urlencoded');
let options = new RequestOptions({
headers: headers
});
return this._http
.post(this.url + 'Datos_Sencibilizacion', params, options)
.map((res: Response) => res.json())
.catch((error: any) => Observable.throw(error.json().error))
}
public logout(): void {
console.log(this.authenticationService.logout()) this.authenticationService.logout().subscribe( response=> {
if(response) {
console.log(response);
this.storageService.logout();
}
}
);
}
;
onSubmit() {
this.sencibilizacionService.postSencibilizacion(this.Dato_sencibilizacion).subscribe( response=> {
if(response.code==200) {
this.authenticationService.logout();
}
else {
console.log(response);
}
}
, error=> {
console.log(<any>error);
}
);
}
;
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<?php
require_once 'vendor/autoload.php';
$app = new \Slim\Slim();
$serverName = '****';
$connectionInfo = array( "database"=>"***", "UID"=>"***", "PWD"=>"***", "Characterset"=>"UTF-8");
$conn = sqlsrv_connect( $serverName, $connectionInfo);
//Configuracion de Cabeceras
header('Access-Control-Allow-Origin: *');
header("Access-Control-Allow-Headers: X-API-KEY, Origin, X-Requested-With, Content-Type, Accept, Access-Control-Request-Method");
header("Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE");
header("Allow: GET, POST, OPTIONS, PUT, DELETE");
$method = $_SERVER['REQUEST_METHOD'];
if($method == "OPTIONS") {
die();
};
$app->get('/Datos_Sencibilizacion', function() use($conn, $app){
$sql = 'SELECT * FROM Datos_Sencibilizacion;';
$insert = sqlsrv_query ($conn, $sql);
$rows = array();
while( $row = sqlsrv_fetch_array( $insert, SQLSRV_FETCH_ASSOC)){
$rows[] = $row;
}
$result = array(
'status' => 'success',
'code' => 200,
'data' => $rows
);
echo json_encode($result);
});
$app->post ('/Datos_Sencibilizacion', function() use($app, $conn){
$json = $app->request->post('json');
$data = json_decode($json, true);
if(!isset($data['Fecha'])){
$data['Fecha']="NULL";
}
if(!isset($data['Nobre_Propietario'])){
$data['Nobre_Propietario']="NULL";
}
if(!isset($data['Nobre_Establecimiento'])){
$data['Nobre_Establecimiento']="NULL";
}
if(!isset($data['Direccion_Establecimiento'])){
$data['Direccion_Establecimiento']="NULL";
}
if(!isset($data['Actividad_Economica'])){
$data['Actividad_Economica']="NULL";
}
if(!isset($data['Telefono_Propietario'])){
$data['Telefono_Propietario']=0;
}
if(!isset($data['Firma'])){
$data['Firma']="0";
}
$query = " INSERT INTO Datos_Sencibilizacion
VALUES (".
"'{$data['Fecha']}',".
"'{$data['Nobre_Propietario']}',".
"'{$data['Nobre_Establecimiento']}',".
"'{$data['Direccion_Establecimiento']}',".
"'{$data['Actividad_Economica']}',".
"{$data['Telefono_Propietario']},".
"'{$data['Firma']}'".
");";
$insert = sqlsrv_query ($conn, $query);
$result = array(
'status' => 'error',
'code' => 404,
'message' => 'Dato NO creado correctamente'
);
if($insert){
$result = array(
'status' => 'success',
'code' => 200,
'message' => 'Dato creado correctamente'
);
}
echo json_encode ($result);
});
$app->run();
?>
In this case the login of my project will be damaged, by removing the CoreModule library Would you open a solution to leave the login without this library?