
<?php
include 'process.php';

if (isset($_GET['edit'])) {
    $id = $_GET['edit'];
    $edit_state = true;
    
    $record = mysqli_query($conn, "SELECT * FROM usersbike WHERE id=$id");
$data = mysqli_fetch_array($record);
  $username = $data['username'];
  
  $phonenumber = $data['phonenumber'];
  $uid = $data['uid'];
  $name = $data['name'];
  $vehicletype = $data['vehicletype'];
  $type = $data['type'];
  $fullname = $data['fullname'];
  $imei = $data['imei'];
      $voltage=$data['voltage'];
    $amp=$data['amp'];
    $kmph=$data['kmph'];
  }
?>
<!DOCTYPE html>
<html>
<head>
  <link rel="stylesheet" type="text/css" href="style.css">
  <title>UsersBikeData</title>
  <link href="landingstyle.css" rel="stylesheet" type="text/css">
		<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.7.1/css/all.css">
</head>
<body class="loggedin">
		<nav class="navtop">
			<div>
				<h1>Sytiqhub</h1>
				<a href="profile.php"><i class="fas fa-user-circle"></i>Profile</a>
				<a href="logout.php"><i class="fas fa-sign-out-alt"></i>Logout</a>
			</div>
		</nav>
<center>
  <?php if (isset($_SESSION['message'])):?>
    <div class="message">
      <?php 
      echo $_SESSION['message']; 
      unset($_SESSION['message']); 
      ?>
    </div>
  <?php endif ?>
 	<div class="content">
			<h2>Users Bike Data</h2>
			</div>
   <form class="form-inline" method="POST" action="process.php">
     <input type="hidden" name="id" value="<?php echo $id; ?>">
     <input type="text" name="username" placeholder="Username" value="<?php echo $username; ?>">
     
     <input type="text" name="phonenumber" placeholder="Mobile Number" value="<?php echo $phonenumber; ?>">
     <input type="text" name="uid" placeholder="User Id" value="<?php echo $uid; ?>">
     <input type="text" name="name" placeholder="Name" value="<?php echo $name; ?>">
     <input type="text" name="vehicletype" placeholder="Vehicle Type" value="<?php echo $vehicletype; ?>">
     <input type="text" name="fullname" placeholder="Fullname" value="<?php echo $fullname; ?>">
     <input type="text" name="imei" placeholder="Imei" value="<?php echo $imei; ?>">
         <input type="text" name="voltage" placeholder="voltage" value="<?php echo $voltage; ?>">
     <input type="text" name="amp" placeholder="amp" value="<?php echo $amp; ?>">
     <input type="text" name="kmph" placeholder="kmph" value="<?php echo $kmph; ?>">
     
     
  <?php if ($edit_state == false): ?>
  <button class="btn" type="submit" name="save" >Save</button>
<?php else: ?>
  <button class="btn" type="submit" name="update" >Update</button>
<?php endif ?>
     
   </form>

<table>
  <tr>
    <th>id</th>
    <th>username</th>
    <th>Password</th>
    <th>phonenumber</th>
    <th>uid</th>
    <th>VehicleName</th>
    <th>voltage</th>
    <th>current</th>
    <th>KMPH</th>
    <th>fullname</th>
    <th>imei</th>
    
   <th> created_at</th>
   
    <th>Action</th>
  </tr>
  <?php
  $result = mysqli_query($conn, "SELECT * FROM usersbike ORDER BY usersbike.created_at DESC");
  //SELECT * FROM `usersbike` ORDER BY `usersbike`.`created_at` DESC   SELECT * FROM usersbike"
$i = 1;
while ($row = mysqli_fetch_assoc($result)) {

  ?>
  <tr>
  <td><?php echo $row["id"]; ?></td>
  <td><?php echo $row["username"]; ?></td>
    <td><?php echo $row["pass"]; ?></td>
  
  <td><?php echo $row["phonenumber"]; ?></td>
  <td><?php echo $row["uid"]; ?></td>
  
  <td><?php echo $row["vehiclename"]; ?></td>
  
   <td><?php echo $row["voltage"]; ?></td>
    <td><?php echo $row["amp"]; ?></td>
     <td><?php echo $row["kmph"]; ?></td>
  <td><?php echo $row["fullname"]; ?></td>
  <td><?php echo $row["imei"]; ?></td>
  <td><?php echo $row["created_at"]; ?></td>

  <td><a href="usersbike.php?edit=<?php echo $row["id"]; ?>" class="edit_btn">Edit</a></td>
  <td><a href="process.php?delete=<?php echo $row["id"]; ?>" class="del_btn">Delete</a></td>
  </tr>
  <?php
  $i++;
}
  ?>
</table>

</center>

	<?php include_once('sidebar.php');?>
</body>
</html>