<?php
session_start();
if (!isset($_SESSION['username'])) {
    echo "<script>window.top.location.href='index.php';</script>"; // Redirect parent window to login page
    exit();
}

include 'connect.php';

?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <!--<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.rtl.min.css">-->
    <link rel="stylesheet" href="css/bootstrap.min.css">
    <link rel="stylesheet" href="fontawesome/css/all.min.css">
    <title>CUSTOMER CRUD OPERATION</title>
</head>
<body>
    <div class="container my-5">
    <button class="btn btn-primary"><a href="add_customer.php" class="text-light">Add New Customer<a></button>
    </div>
    <div class="container my-5">
    <table class="table table-hover">
  <thead>
    <tr>
      <th scope="col">SNo.</th>
      <th scope="col">Customer Name</th>
      <th scope="col">Company</th>
      <th scope="col">Mobile</th>
      <th scope="col">Email</th>
    </tr>
  </thead>
  <tbody>

  <?php
    $sql= "select * from customer_table";
    $result= mysqli_query($conn,$sql);
    if($result){

      //Initialize serial number
      $serealNo = 1;
       
        while($row=mysqli_fetch_assoc($result)){
            $customer_id=$row['customer_id'];
            $cust_name=$row['cust_name'];
            $cust_company=$row['cust_company'];
            $cust_mobile=$row['cust_mobile'];
            $cust_email=$row['cust_email'];
           
            echo '<tr>
  
      <td>'.$serealNo++.'</td>
      <td>'.$cust_name.'</td>
      <td>'.$cust_company.'</td>
      <td>'.$cust_mobile.'</td>
      <td>'.$cust_email.'</td>
    
      <td>
        <button class="btn btn-primary"><a href="update_customers.php?updateid='.$customer_id.'" class="text-light"><i class="fas fa-edit"></i><a></button>
       
    </td>
    </tr>';
            
        }

    }




   ?>
    
    
  </tbody>
</table>

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