<?php
// include "Nav.php";
// Check existence of id parameter before processing further
if(isset($_GET["ID"]) && !empty(trim($_GET["ID"]))){
    // Include config file
    require_once "Connection.php";
    
    // Prepare a select statement
    $sql = "SELECT * FROM master_process_copy WHERE ID = ?";
    
    if($stmt = mysqli_prepare($con, $sql)){
        // Bind variables to the prepared statement as parameters
        mysqli_stmt_bind_param($stmt, "i", $param_id);
        
        // Set parameters
        $param_id = trim($_GET["ID"]);
        
        // Attempt to execute the prepared statement
        if(mysqli_stmt_execute($stmt)){
            $result = mysqli_stmt_get_result($stmt);
    
            if(mysqli_num_rows($result) == 1){
                /* Fetch result row as an associative array. Since the result set
                contains only one row, we don't need to use while loop */
                $row = mysqli_fetch_array($result, MYSQLI_ASSOC);
                
                // Retrieve individual field value
                $proj = $row["PROJECT"];
                $category = $row["CATEGORY"];
                $process = $row["PROCESS"];
            } else{
                // URL doesn't contain valid id parameter. Redirect to error page
                // header("location: error.php");
                exit();
            }
            
        } else{
            echo "Oops! Something went wrong. Please try again later.";
        }
    }
     
    // Close statement
    mysqli_stmt_close($stmt);
    
    // Close connection
    mysqli_close($con);
} else{
    // URL doesn't contain id parameter. Redirect to error page
    // header("location: error.php");
    exit();
}
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Emp_Prod_Benchmark</title>
    <link rel="shortcut icon" href="images/Files_Download.png" type="image/x-icon"/>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <style>
        .wrapper{
            width: 600px;
            margin: 0 auto;
        }
        label{
            font-weight: bold;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
                    <h5 class="mt-5 mb-3">View Record</h5>
                    <div class="form-group">
                        <label>Project:</label><br>
                        <input class="form-control" value="<?php echo $row["PROJECT"];?>" readonly>
                    </div>
                    <div class="form-group">
                        <label>Category:</label><br>
                        <input  class="form-control" value="<?php echo $row["CATEGORY"]; ?>"readonly>
                    </div>
                    <div class="form-group">
                        <label>Process:</label><br>
                        <input class="form-control" value="<?php echo $row["PROCESS"]; ?>" readonly>
                    </div>
                    <div class="form-group">
                        <label>Benchmark:</label><br>
                        <input class="form-control" value="<?php echo $row["BENCHMARK"]; ?>" readonly>
                    </div>
                    <p><a href="add_proj.php" class="btn btn-primary">Back</a></p>
                </div>
            </div>        
        </div>
    </div>
</body>
</html>