Skip to content

Instantly share code, notes, and snippets.

@parzibyte
Created January 17, 2021 22:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save parzibyte/87a5e9315791592b9fff22137cf63c0a to your computer and use it in GitHub Desktop.
Save parzibyte/87a5e9315791592b9fff22137cf63c0a to your computer and use it in GitHub Desktop.
<?php
$cargaUtil = json_decode(file_get_contents("php://input"));
// Si no hay datos, salir inmediatamente indicando un error 500
if (!$cargaUtil) {
// https://parzibyte.me/blog/2021/01/17/php-enviar-codigo-error-500/
http_response_code(500);
exit;
}
// Extraer valores
$nombre = $cargaUtil->nombre;
$precio = $cargaUtil->precio;
$descripcion = $cargaUtil->descripcion;
include_once "funciones.php";
$respuesta = guardarProducto($nombre, $precio, $descripcion);
// Devolver al cliente la respuesta de la función
echo json_encode($respuesta);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment