File "realizar.php"

Full Path: C:/wamp64/www/RegistroEquipos2/backend/mantenimiento/realizar.php
File size: 1.11 KB
MIME-type: text/x-php
Charset: utf-8

<?php
session_start();
header('Content-Type: application/json');
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Methods: POST, OPTIONS');

$host = '192.200.100.40';
$db = 'sistemas';
$user = 'SANMARINO';
$pass = 'sanmarino2021*';

try {
    $pdo = new PDO("mysql:host=$host;dbname=$db;charset=utf8mb4", $user, $pass, [
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
    ]);

    $data = json_decode(file_get_contents('php://input'), true);
    if (!$data) {
        echo json_encode(['status' => 'error', 'mensaje' => 'Datos no vĂ¡lidos']);
        exit;
    }

    $id = $data['id'] ?? 0;

    if (!$id) {
        echo json_encode(['status' => 'error', 'mensaje' => 'ID no proporcionado']);
        exit;
    }

    $stmt = $pdo->prepare("UPDATE mantenimientos SET estado = 'realizado', fecha_realizada = CURDATE() WHERE id = ?");
    $stmt->execute([$id]);

    echo json_encode(['status' => 'success', 'mensaje' => 'Mantenimiento marcado como realizado']);

} catch (PDOException $e) {
    echo json_encode(['status' => 'error', 'mensaje' => $e->getMessage()]);
}
?>