<?php
include('mysqli_con.php');
//show all user
if(isset($_POST['show'])){
$buyer_id = $_POST['show'];
$sqlShowUser = "SELECT * FROM buyer ";
$showData = mysqli_query($conn, $sqlShowUser);

if(mysqli_num_rows($showData) > 0){
  while($row = mysqli_fetch_assoc($showData)){
?>
<form class="form-inline navbar-search" method="post" action="userSearchDeletePro.php" >
  <tr><td><center><h5><?php echo $row["buyer_id"]; ?> </h5><center></td><td><center><h5><?php echo $row["first_name"];?> <?php echo $row["last_name"];?> </h5><center></td>
    <td><center><h5><?php echo  $row["email"]; ?></h5><center></td>
        <td><a onclick="return confirm('Are You Sure ?')">
          <center><button type="submit" class="btn" name ="delete" value="<?php echo $row["buyer_id"]; ?>" >DELETE</button></center>
        </td></tr></td>
  </form>
<?php }}}

//delete user and their items
if(isset($_POST['delete'])){
  $buyerid = $_POST['delete'];
  $deleteUserItem = "DELETE FROM buyer WHERE buyer_id = '$buyerid'";
  $delete = "DELETE FROM items WHERE buyer_id = '$buyerid'";
  mysqli_query($conn, $deleteUserItem);
  mysqli_query($conn, $delete);
  ?>
  <meta http-equiv="refresh" content="0; URL='adminUser.php'">
  <?php
}

// search user by id
if(isset($_POST['search'])){
  $searchUser= $_POST['searchIDUser'];
  $sqlSearchUser = "SELECT * FROM buyer WHERE buyer_id LIKE '%".$searchUser."%'";
  $searchResult = mysqli_query($conn, $sqlSearchUser);
  while($row = mysqli_fetch_array($searchResult)){?>
    <form class="form-inline navbar-search" method="post" action="userSearchDeletePro.php" >
      <tr><td><center><h5><?php echo $row["buyer_id"]; ?> </h5><center></td><td><center><h5><?php echo $row["first_name"];?> <?php echo $row["last_name"];?> </h5><center></td>
        <td><center><h5><?php echo  $row["email"]; ?></h5><center></td>

            <td><a onclick="return confirm('Are You Sure ?')">
              <center><button type="submit" class="btn" name ="delete" value="<?php echo $row["buyer_id"]; ?>" >DELETE</button></center>
            </td></tr></td>
      </form>
      <?php
  }} else {

  }
  ?>
