1ra Versión
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
header('Content-Type: application/json');
|
||||
error_reporting(E_ALL);
|
||||
ini_set("display_errors", 1);
|
||||
|
||||
require_once 'conexion.php';
|
||||
|
||||
if ($conexion->connect_error) {
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"error" => "Error de conexión: " . $conexion->connect_error
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$raw = file_get_contents("php://input");
|
||||
// file_put_contents("log_debug.txt", "RAW:\n" . $raw . "\n", FILE_APPEND); <-- línea comentada / eliminada
|
||||
|
||||
$data = json_decode($raw, true);
|
||||
|
||||
if (!$data) {
|
||||
echo json_encode([
|
||||
"success" => false,
|
||||
"error" => "JSON inválido",
|
||||
"raw" => $raw
|
||||
]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$id = isset($data['id']) ? (int)$data['id'] : null;
|
||||
$nombre = $data['nombre'] ?? null;
|
||||
$telefono = $data['telefono'] ?? null;
|
||||
|
||||
if (!$id || !$nombre || !$telefono) {
|
||||
echo json_encode(["success" => false, "error" => "Datos incompletos"]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt = $conexion->prepare("UPDATE proveedores SET Nombre = ?, Telefono = ? WHERE ID_Proveedor = ?");
|
||||
if (!$stmt) {
|
||||
echo json_encode(["success" => false, "error" => "Error en prepare(): " . $conexion->error]);
|
||||
exit;
|
||||
}
|
||||
|
||||
$stmt->bind_param("ssi", $nombre, $telefono, $id);
|
||||
|
||||
if ($stmt->execute()) {
|
||||
echo json_encode(["success" => true]);
|
||||
} else {
|
||||
echo json_encode(["success" => false, "error" => $stmt->error]);
|
||||
}
|
||||
|
||||
$stmt->close();
|
||||
$conexion->close();
|
||||
Reference in New Issue
Block a user