HEX
Server: Apache/2.4.46 (Ubuntu)
System: Linux localhost 5.11.0-49-generic #55-Ubuntu SMP Wed Jan 12 17:36:34 UTC 2022 x86_64
User: root (0)
PHP: 7.4.16
Disabled: pcntl_alarm,pcntl_fork,pcntl_waitpid,pcntl_wait,pcntl_wifexited,pcntl_wifstopped,pcntl_wifsignaled,pcntl_wifcontinued,pcntl_wexitstatus,pcntl_wtermsig,pcntl_wstopsig,pcntl_signal,pcntl_signal_get_handler,pcntl_signal_dispatch,pcntl_get_last_error,pcntl_strerror,pcntl_sigprocmask,pcntl_sigwaitinfo,pcntl_sigtimedwait,pcntl_exec,pcntl_getpriority,pcntl_setpriority,pcntl_async_signals,pcntl_unshare,
Upload Files
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");
}


?>