File: /var/www/html/balajiproperties.org/form-submittintg.php
<?php
if($_SERVER["REQUEST_METHOD"] == "POST"){
include('send-mail.php');
// Database configuration
$host = "localhost"; // DB host
$db_name = "balaji_properties"; // DB name
$username = "root"; //DB username
$password = "cccdev@1234"; //DB password
// Create database connection
$conn = new mysqli($host, $username, $password, $db_name);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Check if form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get form data
$name = trim($_POST['wpforms']['fields'][0]);
$email = trim($_POST['wpforms']['fields'][1]);
$phone = trim($_POST['wpforms']['fields'][4]); // phone field
$message = trim($_POST['wpforms']['fields'][2]); // message field
$hp = trim($_POST['wpforms']['hp']); // honeypot
$page_title = trim($_POST['page_title']); // Page Name
// Basic validation
$errors = [];
if ($hp !== "") {
$errors[] = "Bot submission detected.";
}
if (empty($name)) $errors[] = "Name is required.";
if (empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL)) $errors[] = "Valid email is required.";
if (empty($phone)) {
$errors[] = "Phone number is required.";
} elseif (!preg_match('/^\d{10}$/', $phone)) {
$errors[] = "Please enter a valid 10-digit phone number.";
}
if (empty($message)) $errors[] = "Message is required.";
if (empty($errors)) {
// Prepare and bind
sendMail($name, $email, $phone, $message, $page_title);
sendUserMail($name, $email);
$stmt = $conn->prepare("INSERT INTO contact_form_submissions (name, email, phone, message, hp, page_title) VALUES (?, ?, ?, ?, ?, ?)");
$stmt->bind_param("ssssss", $name, $email, $phone, $message, $hp, $page_title);
if ($stmt->execute()) {
// Redirect to thank-you page
header("Location: thank-you");
exit();
} else {
echo "Error: " . $stmt->error;
}
$stmt->close();
} else {
foreach ($errors as $error) {
echo "<p style='color:red;'>$error</p>";
}
}
}
$conn->close();
}else{
header("Location: index");
}
?>