<?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';
if(isset($_POST['submit'])){
    $sup_name=$_POST['sup_name'];
    $sup_company=$_POST['sup_company'];
    $sup_mobile=$_POST['sup_mobile'];
    $sup_email=$_POST['sup_email'];
    $product_desc=$_POST['product_desc'];
    
    $sql = "insert into supplier_table (sup_name, sup_company, sup_mobile, sup_email, product_desc) values ('$sup_name','$sup_company','$sup_mobile','$sup_email','$product_desc')";
    $result=mysqli_query($conn, $sql);
    if($result){
        //echo "Data inserted succesfully";
        header('location: display_supplier.php');
    }else{
        die(mysqli_error($conn));
    }
}

?>

<!doctype html>
<html lang="en" dir="ltr">
  <head>
    <!-- Required meta tags -->
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <!-- Bootstrap CSS -->
<!--<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">

    <title>ADD SUPPLIER</title>
  </head>
  <body>
    <div class="container my-5"> 

    <h3>Please fill all the textboxes to add a new Supplier to the system</h3>

        <form method="POST">
            <div class="mb-3">
                <label for="formGroupExampleInput" class="form-label">Fullname:</label>
                <input type="text" class="form-control" name="sup_name" autocomplete="off" placeholder="Enter supplier name">
            </div>
            <div class="mb-3">
                <label for="formGroupExampleInput" class="form-label">Company:</label>
                <input type="text" class="form-control" name="sup_company" autocomplete="off" placeholder="Enter supplier company">
            </div>
            <div class="mb-3">
                <label for="formGroupExampleInput" class="form-label">Mobile No:</label>
                <input type="text" class="form-control" name="sup_mobile" autocomplete="off" placeholder="Enter supplier Mobile No.">
            </div>
            <div class="mb-3">
                <label for="formGroupExampleInput2" class="form-label">Email:</label>
                <input type="email" class="form-control" name="sup_email" autocomplete="off" placeholder="Enter supplier email">
            </div>
            <div class="mb-3">
                <label for="formGroupExampleInput" class="form-label">Description:</label>
                <textarea name="product_desc" class="form-control" rows="2" cols="50" autocomplete="off" ></textarea>
                
            </div>
           

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

    </div>

    <script src="js/jquery.min.js"></script>
<script src="js/bootstrap.bundle.min.js"></script>
  </body>
</html>