<?php
// Database connection details
$servername = "localhost";
$username = "root"; // Change this to your database username
$password = ""; // Change this to your database password
$dbname = "my_database";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

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

// Get item from form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
  $name = $_POST["name"];

  // Prepare SQL statement to prevent SQL injection
  $stmt = $conn->prepare("INSERT INTO items (name) VALUES (?)");
  $stmt->bind_param("s", $name);

  // Execute and check success
  if ($stmt->execute()) {
    echo "Item successfully added!";
  } else {
    echo "Error: " . $stmt->error;
  }

  // Close connection
  $stmt->close();
}

$conn->close();
