<?php include('common/header.php'); ?>
  <!-- Main Sidebar Container -->
<?php include('common/sidenav.php'); ?>


  <!-- Content Wrapper. Contains page content -->
<!--For save data-->

<?php
 include_once ('includes/config.php');
   
// Check connection
    if ($con->connect_error) {
    die("Connection failed: " . $con->connect_error);
    } 

if(isset($_POST['submit']))
{
 

$id=$_GET['id'];
$name =$_POST['name'];
$regno =$_POST['reg_no'];





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

 

     $sql="Update `vehicles` SET `vname`='".$name."' WHERE vehicle_id
   ='$id'";


  
if ($con->multi_query($sql) === TRUE) 
{
//    echo "Record Updated successfully";

  
 echo "<div class='container'><div class='custom-alert'>Record Successfully Updated!</div></div>";
        echo "<script>setTimeout(function() { window.location.href='vehicle.php'; }, 1000);</script>";


} 

else {
    echo "Error: " . $sql . "<br>" . $con->error;
  }


//echo "<script>(window.location.href='vehicle.php?success');</script>";
$con->close();
}
 ?>
 
 
  

  <div class="content-wrapper">

 <!-- Content Header (Page header) -->
    <section class="content-header">
      <div class="container-fluid">
        <div class="row mb-2">
          <div class="col-sm-6">
            <h1>Vehicle</h1>
          </div>
          <div class="col-sm-6">
            <ol class="breadcrumb float-sm-right">
              <li class="breadcrumb-item"><a href="vehicle.php">Dataview</a></li>
             <li class="breadcrumb-item active"><a href="dashboard.php">Dashboard</a></li>
            </ol>
          </div>
        </div>
      </div><!-- /.container-fluid -->
    </section>

 <!-- Main content -->
    <section class="content">
      <div class="container-fluid">
        <!-- SELECT2 EXAMPLE -->
        <div class="card card-default">
          <div class="card-header">
            <h3 class="card-title">Edit Info</h3>
<?php
                    include('includes/config.php');
                    
        
       $id=$_GET['id'];
    $result = mysqli_query($con, "SELECT * FROM `vehicles` WHERE vehicle_id='$id'");
   while($row = mysqli_fetch_assoc($result)) {
                
                    
            ?>
            <div class="card-tools">
              <button type="button" class="btn btn-tool" data-card-widget="collapse"><i class="fas fa-minus"></i></button>
              <button type="button" class="btn btn-tool" data-card-widget="remove"><i class="fas fa-times"></i></button>
            </div>
          </div>
          <!-- /.card-header -->
          <div class="card-body">
          	<form method="post"  enctype="multipart/form-data">
             <div class="row">
          	        <div class="col-md-6">
          	            <div class="form-group">
          	                  <label>Name</label>
                 <input type="text" placeholder="Vehicle Name" required="required" class="form-control" name="name" value="<?php echo $row['vname']; ?>">
          	            </div>
          	            
          	        </div>
          	        
                    
          	      
          	 
          	    </div>
       
          
          
          
          
          <?php } ?>
            
        
          </div>
          <!-- /.card-body -->
          <div class="card-footer">
           <button type="submit" name="submit" class="btn btn-danger">Submit</button>
          </div>
</form>
        <!-- /.card -->


  
        <!-- /.row -->
      </div><!-- /.container-fluid -->
    </section>
    <!-- /.content -->



  </div>
  <!-- /.content-wrapper -->






<?php include('common/footer.php'); ?>