<?php
include 'header.php';
 
if (isset($_GET['edit'])) {
  $userEdit = $_GET['edit'];

  $sql = mysqli_query($link, "SELECT * FROM  users WHERE id = '$userEdit' ");
    if (mysqli_num_rows($sql) > 0) {
    $row = mysqli_fetch_assoc($sql);
    $_fname = $row['fname'];  
    $_email =  $row['email'];
    $_username =  $row['username'];  
    $_phone =  $row['phone'];
    $_gender =  $row['gender'];
    $_address =  $row['address'];
    $_city = $row['city'];
    $_country = $row['country'];
    $_password = $row['password'];
    $_date = $row['date'];
  }
}


  if (isset($_POST['submit'])) {
  $fname = $_POST['fname'];  
  $email =  $_POST['email'];
  $username =  $_POST['username'];  
  $phone =  $_POST['phone'];
  $gender =  $_POST['gender'];
  $address =  $_POST['address'];
  $city = $_POST['city'];
  $country = $_POST['country'];
  $password = $_POST['password'];
    
  $sql = mysqli_query($link, "UPDATE users SET fname = '$fname', email = '$email', username = '$username', phone = '$phone', gender = '$gender', address = '$address', city = '$city', country = '$country', password = '$password' WHERE id = '$userEdit' ");

  if ($sql) {
    echo "<script>
    alert('updated successfully');
    window.location.href = 'activeuser.php';
    </script>";
  }
}
    
?>

 <!-- Content wrapper scroll start -->
        <div class="content-wrapper-scroll">

          <!-- Content wrapper start -->
          <div class="content-wrapper">

            <!-- Row start -->
            <div class="row">
              <div class="col-sm-12 col-12">

                <!-- Card start -->
                <div class="card">
                  <div class="card-header">
                    <div class="card-title">Edit User profile</div>
                  </div>
                  <div class="card-body">

                    <!-- Row start -->
                    <form method="POST" action="" >
                    <div class="row">
                      <div class="col-xxl-3 col-xl-3 col-lg-4 col-md-4 col-sm-4 col-12">
                        <div class="mb-3">
                          <label for="inputName" class="form-label">Full Name</label>
                          <input type="text" class="form-control" id="inputName" name="fname" value="<?php echo $_fname  ?>">
                        </div>
                      </div>
                      <div class="col-xxl-3 col-xl-3 col-lg-4 col-md-4 col-sm-4 col-12">
                        <div class="mb-3">
                          <label for="inputEmail" class="form-label">Email</label>
                          <input type="text" class="form-control" id="inputEmail" name="email" value="<?php echo $_email  ?>">
                        </div>
                      </div>
                      <div class="col-xxl-3 col-xl-3 col-lg-4 col-md-4 col-sm-4 col-12">
                        <div class="mb-3">
                          <label for="inputNumber" class="form-label">Username</label>
                          <input type="text" class="form-control" id="inputNumber" name="username" value="<?php echo $_username  ?>">
                        </div>
                      </div>
                      <div class="col-xxl-3 col-xl-3 col-lg-4 col-md-4 col-sm-4 col-12">
                        <div class="mb-3">
                          <label for="inputCompanyName" class="form-label">Phone</label>
                          <input type="text" class="form-control" id="inputCompanyName" name="phone" value="<?php echo $_phone ?>">
                        </div>
                      </div>
                      <div class="col-xxl-3 col-xl-3 col-lg-4 col-md-4 col-sm-4 col-12">
                        <div class="mb-3">
                          <label for="inputBusinessAddress" class="form-label">Gender</label>
                          <input type="text" class="form-control" id="inputBusinessAddress" name="gender" value="<?php echo $_gender  ?>">
                        </div>
                      </div>
                      <div class="col-xxl-3 col-xl-3 col-lg-4 col-md-4 col-sm-4 col-12">
                        <div class="mb-3">
                          <label for="inputProvince" class="form-label">Address</label>
                          <input type="text" class="form-control" id="inputProvince" name="address" value="<?php echo $_address ?>">
                        </div>
                      </div>

                         <div class="col-xxl-3 col-xl-3 col-lg-4 col-md-4 col-sm-4 col-12">
                        <div class="mb-3">
                          <label for="inputProvince" class="form-label">City</label>
                          <input type="text" class="form-control" id="inputProvince" name="city" value="<?php echo $_city  ?>">
                        </div>
                      </div>
                    
                      <div class="col-xxl-3 col-xl-3 col-lg-4 col-md-4 col-sm-4 col-12">
                        <div class="mb-3">
                          <label for="inputPostalCode" class="form-label">Country</label>
                          <input type="text" class="form-control" id="inputPostalCode" name="country" value="<?php echo $_country  ?>">
                        </div>
                      </div>

                       <div class="col-xxl-3 col-xl-3 col-lg-4 col-md-4 col-sm-4 col-12">
                        <div class="mb-3">
                          <label for="inputPostalCode" class="form-label">Password</label>
                          <input type="text" class="form-control" id="inputPostalCode" name="password" value="<?php echo $_password  ?>">
                        </div>
                      </div>
                      
                    </div>
                    <!-- Row end -->

                      <button class="btn btn-success" name="submit" type="submit">Submit</button>

                    <!-- Form actions footer end -->

                    </form>

                  </div>
                </div>
                <!-- Card end -->

              </div>

            </div>
            <!-- Row end -->

          </div>
          <!-- Content wrapper end -->


<?php 
 include 'footer.php';
?>