<?php include 'rr_inventory.php';

$id = $_POST['id'] ?? null;

if ($id) {
    $stmt = $mysqli->prepare("
        UPDATE rolling_stock SET
        road=?, road_number=?, type=?, color=?, owner=?, manufacturer=?
        WHERE id=?
    ");
    $stmt->bind_param("ssssssi",
        $_POST['road'], $_POST['road_number'], $_POST['type'],
        $_POST['color'], $_POST['owner'], $_POST['manufacturer'], $id
    );
} else {
    $stmt = $mysqli->prepare("
        INSERT INTO rolling_stock
        (road, road_number, type, color, owner, manufacturer)
        VALUES (?,?,?,?,?,?)
    ");
    $stmt->bind_param("ssssss",
        $_POST['road'], $_POST['road_number'], $_POST['type'],
        $_POST['color'], $_POST['owner'], $_POST['manufacturer']
    );
}

$stmt->execute();

header("Location: index.php");
