<?php
// Assuming you've established MySQL connection

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "elvieg_editpost";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}


if(isset($_GET['ctrlnum'])) {
    $selectedId = $_GET['ctrlnum'];

    // Query to fetch data from MySQL based on selected record
    $query = "SELECT * FROM permbo2022to2026 WHERE ctrlnum = ?";
    $stmt = $pdo->prepare($query);
    $stmt->execute([$selectedId]);
    $record = $stmt->fetch(PDO::FETCH_ASSOC);

    // Generate HTML for form fields using fetched data
    if($record) {
        $html = "";
        foreach ($record as $key => $value) {
            // Assuming column names match form field names
            $html .= "<label for='$key'>$key:</label>";
            $html .= "<input type='text' name='$key' id='$key' value='$value'><br>";
        }
        echo $html;
    } else {
        echo "No record found.";
    }
}
?>
