<?php
// Replace with your database credentials
include("database.php");


// Process form submission
if (isset($_POST['submit'])) {
  // Escape user inputs to prevent SQL injection
  $fullname = mysqli_real_escape_string($conn, $_POST['fullname']);
  $email = mysqli_real_escape_string($conn, $_POST['email']);
  $phone = mysqli_real_escape_string($conn, $_POST['phone']);

  // Insert visitor data into visitors table
  $sql = "INSERT INTO visitors (fullname, email, phone)
          VALUES ('$fullname', '$email', '$phone')";

  if ($conn->query($sql) === FALSE) {
    echo "Error: " . $sql . "<br>" . $conn->error;
    echo "Visitor data not saved";
  } else {
    echo "Visitor data saved successfully";
    header("Location: ../index.html");
    exit();
  }
}

// Close connection
$conn->close();
?>
