<?php
include_once 'shikanisha.kts.php';

// Get the data from the AJAX request
$name = $_POST['vendor_name'];
$address = $_POST['address'];
$phone = $_POST['phone_number'];
$email = $_POST['email'];
$company = $_POST['company'];

// Insert the data into the database
$sql = "INSERT INTO `vendors`(`vendor_name`, `vendor_address`, `vendor_phone`, `vendor_email`, `company`) VALUES ('$name', '$address', '$phone', '$email', '$company')";

if ($conn->query($sql) === TRUE) {
  $vendor_id = mysqli_insert_id($conn);
  $sql = "INSERT INTO `vendor_debts`(`id`,`vendor_id`, `amount_owed`) VALUES ('$vendor_id','$vendor_id', '0')";
  if ($conn->query($sql) === TRUE) {
    echo "Vendor Registered successfully";
  } else {
    echo "Error: " . $sql . "<br>" . $conn->error;
  }
} else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}
?>
