<?php
include("db.php");
if(isset($_POST['update'])){
$address = $_POST['address'];
$update = mysqli_query($conn, "UPDATE clients SET address='$address' WHERE name='$_POST[name]'ORDER BY id DESC ");
}
?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, shrink-to-fit=no">
    <title>Driver Logbook</title>
    <link rel="stylesheet" href="assets/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="assets/fonts/font-awesome.min.css">
    <link rel="stylesheet" href="assets/css/Registration-Form-with-Photo.css">
    <link rel="stylesheet" href="assets/css/styles.css">
</head>
<div class="login-clean" style="height: 760px;background-image: url(&quot;assets/img/star-sky.jpg&quot;);">
  <div class="form-container" style="padding-top:60px">
  <div class="card" style=" max-width:900px; width:80%; margin:auto; border-radius:20px;">
  <div class="card-header">
    <?php
    $name = mysqli_query($conn, "SELECT * from clients where name='$_POST[name]'");
    $get = mysqli_fetch_array($name);
    ?>
    <table class="table">
      <tr>
        <th>Client Name</th><th>Address</th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th><th></th>
      </tr>
      <tr>
  <td><h5 class="mb-0" style="text-align:left; float:left;"><?php echo $get['name']?></h5></td>
  <td>
    <form action="client-profile.php" method="POST">
      <?php if(!empty($get['address'])){
    echo $get['address'];}else{?>
    <input  type="text" placeholder="Enter Address" name="address">
    <input  type="hidden"  name="name" value="<?php echo $get['name']?>">
    <?php } ?>
    <input type="submit" name="update" value="update" class="btn btn-info">
    <a href="clients.php" class="btn btn-success">Back</a>
  </td>
  </tr>
  </table>
</form>
  </div>
  <div class="card-body" style="height:480px; overflow-y:scroll; overflow-x:hidden;">
    <table class="table table-striped" >
      <tr>
        <th>Car Used</th><th>Driver</th><th>Job/Employee Number</th><th>Distance travelled</th>
      </tr>
    <?php  $result = mysqli_query($conn, "SELECT car,username,job,start_mileage,end_mileage FROM trips WHERE client='$_POST[name]'ORDER BY id DESC");
    while($row = mysqli_fetch_array($result)){
    $mileage = $row['end_mileage'] - $row['start_mileage'];?>
    <div style="overflow-y:scroll; overflow-x:hidden;">
      <tr>
        <td><?php echo $row['car'];?></td>
        <td><?php echo $row['username'];?></td>
        <td><?php echo $row['job'];?></td>
        <td><?php echo $mileage;?></td>
        <?php
      }?>
      </tr>
</div>
    </table>


  </div>
</div>
</body>

</html>
