<?php include '/etc/rr_inventory.php';

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

$row = [
    'road' => '', 'road_number' => '', 'type' => '',
    'color' => '', 'owner' => '', 'manufacturer' => ''
];

if ($id) {
    $res = $mysqli->query("SELECT * FROM rolling_stock WHERE id=$id");
    $row = $res->fetch_assoc();
}
?>

<form method="post" action="save.php">
<input type="hidden" name="id" value="<?= $id ?>">

Road: <input name="road" value="<?= $row['road'] ?>"><br>
Number: <input name="road_number" value="<?= $row['road_number'] ?>"><br>
Type: <input name="type" value="<?= $row['type'] ?>"><br>
Color: <input name="color" value="<?= $row['color'] ?>"><br>
Owner: <input name="owner" value="<?= $row['owner'] ?>"><br>
Manufacturer: <input name="manufacturer" value="<?= $row['manufacturer'] ?>"><br>

<input type="submit">
</form>

<?php if ($id): ?>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?= $id ?>">
<input type="file" name="photo">
<input type="submit" value="Upload Photo">
</form>
<?php endif; ?>
