<?php
// Connect to database
require_once"shikanisha.kts.php";

// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}

// Create table if not exists
$create_table_query = "CREATE TABLE IF NOT EXISTS expense_type (
                        id INT(11) NOT NULL AUTO_INCREMENT,
                        name VARCHAR(255) NOT NULL,
                        PRIMARY KEY (id)
                      )";
if ($conn->query($create_table_query) === false) {
  die("Table creation failed: " . $conn->error);
}

// Check if form submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  // Prepare and bind statement
  $stmt = $conn->prepare("INSERT INTO expense_type (name) VALUES (?)");
  $stmt->bind_param("s", $name);

  // Set parameters and execute
  $name = $_POST["name"];
  $stmt->execute();

  // Close statement and connection
  $stmt->close();
  $conn->close();

  // Return success message
  echo "Record added successfully";
}
?>
