<?php

use FontLib\Table\Type\head;

include('connection.php');

if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $platformId = $_POST["id"];
    $newPlatform = $_POST["newPlatform"];

    // Validate and sanitize the input (You can add more validation as needed)
    $platformId = intval($platformId); // Convert to integer
    $newPlatform = htmlspecialchars($newPlatform);

    // Check if the platform exists
    $checkSql = "SELECT id FROM add_platform WHERE id = $platformId";
    $checkResult = mysqli_query($conn, $checkSql);

    if (mysqli_num_rows($checkResult) > 0) {
        // Update the platform name
        $updateSql = "UPDATE add_platform SET name = '$newPlatform' WHERE id = $platformId";

        if (mysqli_query($conn, $updateSql)) {

            // echo "Platform updated successfully!";
            header("Location:add_platform.php");

        } else {
            echo "Error updating platform: " . mysqli_error($conn);
        }
    } else {
        echo "Platform not found.";
    }

    // Close the database connection
    mysqli_close($conn);
}
?>
