<?php

//https://www.tutorialrepublic.com/php-tutorial/php-mysql-crud-application.php#

//error_reporting(E_ALL);
//ini_set("display_errors", 1);

if(isset($_GET["id"]) )
{

    require_once "config.php";

    //define('DB_SERVER', 'analogdepat.mysql.db');
    //define('DB_USERNAME', 'analogdepat');
    //define('DB_PASSWORD', 'Un92pac007');
    //define('DB_NAME', 'analogdepat');
 
    /* Attempt to connect to MySQL database */
    /*$link = mysqli_connect(DB_SERVER, DB_USERNAME, DB_PASSWORD, DB_NAME);
 
    // Check connection
    if($link === false)
    {
        die("ERROR: Could not connect. " . mysqli_connect_error());
    }*/

    $sql = "SELECT * FROM employees WHERE id = '3'";
    
    $result = $link->query($sql);

    if ($result->num_rows > 0) 
    {
        /*while($row = $result->fetch_assoc()) 
        {
            echo "id: " . $row["id"]. " - Name: " . $row["name"] . " " . $row["address"].  " " . $row["salary"]. "<br>";
        }*/

        $row = $result->fetch_assoc();

       $name = $row["name"];
       $address = $row["address"];
       $salary= $row["salary"];

       echo " --- " . $name ." " .$address ." " .$salary;

    } 
    else 
    {
        echo "0 results";
    }

    echo "FIN....";
}
?>  

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>View Record</title>
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <style>
        .wrapper{
            width: 600px;
            margin: 0 auto;
        }
    </style>
</head>
<body>
    <div class="wrapper">
        <div class="container-fluid">
            <div class="row">
                <div class="col-md-12">
                    <h1 class="mt-5 mb-3">View Record</h1>
                    <div class="form-group">
                        <label>Name</label>
                        <p><b><?php echo $name; ?></b></p>
                    </div>
                    <div class="form-group">
                        <label>Address</label>
                        <p><b><?php echo $row["address"]; ?></b></p>
                    </div>
                    <div class="form-group">
                        <label>Salary</label>
                        <p><b><?php echo $row["salary"]; ?></b></p>
                    </div>
                    <p><a href="index.php" class="btn btn-primary">Back</a></p>
                </div>
            </div>        
        </div>
    </div>
</body>
</html>

