<!DOCTYPE html><?php

<html lang="en">// Simple test to check contact form functionality

<head>session_start();

    <meta charset="UTF-8">require_once 'config.php';

    <meta name="viewport" content="width=device-width, initial-scale=1.0">

    <title>Contact Form Test - Shubank</title>echo "<h2>Testing Contact Form Session Storage</h2>";

    <style>

        body { font-family: Arial, sans-serif; margin: 20px; }// Create contacts table if it doesn't exist (for testing)

        .container { max-width: 800px; margin: 0 auto; }$create_table_query = "CREATE TABLE IF NOT EXISTS contacts (

        .form-group { margin-bottom: 15px; }    id INT PRIMARY KEY AUTO_INCREMENT,

        label { display: block; margin-bottom: 5px; font-weight: bold; }    name VARCHAR(100) NOT NULL,

        input, textarea, select { width: 100%; padding: 10px; border: 1px solid #ddd; border-radius: 5px; }    email VARCHAR(100) NOT NULL,

        button { background: #007bff; color: white; padding: 12px 24px; border: none; border-radius: 5px; cursor: pointer; }    phone VARCHAR(20) NOT NULL,

        button:hover { background: #0056b3; }    subject VARCHAR(200) NOT NULL,

        .alert { padding: 15px; margin: 10px 0; border-radius: 5px; }    message TEXT NOT NULL,

        .alert-success { background: #d4edda; color: #155724; border: 1px solid #c3e6cb; }    preferred_contact VARCHAR(20) NOT NULL,

        .alert-error { background: #f8d7da; color: #721c24; border: 1px solid #f5c6cb; }    ip_address VARCHAR(45),

        .debug { background: #f8f9fa; padding: 15px; margin: 20px 0; border-radius: 5px; border: 1px solid #dee2e6; }    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,

    </style>    status ENUM('new', 'replied', 'resolved') DEFAULT 'new'

</head>)";

<body>mysqli_query($link, $create_table_query);

    <div class="container">

        <h1>Contact Form Test Page</h1>// Check if session data exists

        <p>This is a test page to debug contact form functionality.</p>if (isset($_SESSION['contact_form'])) {

            echo "<h3>✅ Contact Form Data Found in Session:</h3>";

        <?php    echo "<pre>";

        if ($_POST) {    print_r($_SESSION['contact_form']);

            echo '<div class="debug">';    echo "</pre>";

            echo '<h3>Form Submission Debug:</h3>';    

            echo '<pre>' . print_r($_POST, true) . '</pre>';    // Generate WhatsApp message for testing

                $data = $_SESSION['contact_form'];

            // Test database connection    $whatsapp_message = "🎯 *New Contact from Shubank Website*\n\n";

            include 'config.php';    $whatsapp_message .= "👤 *Name:* " . $data['name'] . "\n";

            if ($conn) {    $whatsapp_message .= "📧 *Email:* " . $data['email'] . "\n";

                echo '<p style="color: green;">✓ Database connection successful</p>';    $whatsapp_message .= "📱 *Phone:* " . $data['phone'] . "\n";

                    $whatsapp_message .= "📋 *Subject:* " . $data['subject'] . "\n";

                // Test contact table existence    $whatsapp_message .= "💬 *Message:* " . $data['message'] . "\n";

                $check_table = "SHOW TABLES LIKE 'contacts'";    $whatsapp_message .= "📞 *Preferred Contact:* " . ucfirst($data['preferred_contact']) . "\n";

                $result = mysqli_query($conn, $check_table);    $whatsapp_message .= "🕒 *Time:* " . $data['submitted_at'] . "\n\n";

                if (mysqli_num_rows($result) > 0) {    $whatsapp_message .= "Please respond promptly to this inquiry.";

                    echo '<p style="color: green;">✓ Contacts table exists</p>';    

                } else {    echo "<h3>📱 WhatsApp Message Preview:</h3>";

                    echo '<p style="color: red;">✗ Contacts table does not exist</p>';    echo "<div style='background: #f0f0f0; padding: 15px; border-radius: 8px; white-space: pre-line;'>";

                }    echo $whatsapp_message;

            } else {    echo "</div>";

                echo '<p style="color: red;">✗ Database connection failed</p>';    

            }    echo "<h3>🔗 WhatsApp Link:</h3>";

            echo '</div>';    $whatsapp_url = "https://wa.me/918905245890?text=" . urlencode($whatsapp_message);

        }    echo "<a href='" . $whatsapp_url . "' target='_blank' style='background: #25d366; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px;'>Open in WhatsApp</a>";

        ?>    

        } else {

        <form method="POST" action="">    echo "<p>❌ No contact form data found in session. Please submit the contact form first.</p>";

            <div class="form-group">}

                <label for="name">Full Name *</label>

                <input type="text" id="name" name="name" required // Show recent contacts from database (last 5)

                       value="<?php echo isset($_POST['name']) ? htmlspecialchars($_POST['name']) : 'Test User'; ?>">echo "<h3>📊 Recent Contacts from Database:</h3>";

            </div>$recent_query = "SELECT name, email, subject, created_at FROM contacts ORDER BY created_at DESC LIMIT 5";

            $result = mysqli_query($link, $recent_query);

            <div class="form-group">

                <label for="email">Email Address *</label>if ($result && mysqli_num_rows($result) > 0) {

                <input type="email" id="email" name="email" required     echo "<table style='border-collapse: collapse; width: 100%; margin: 10px 0;'>";

                       value="<?php echo isset($_POST['email']) ? htmlspecialchars($_POST['email']) : 'test@example.com'; ?>">    echo "<tr style='background: #f0f0f0;'>";

            </div>    echo "<th style='border: 1px solid #ddd; padding: 8px;'>Name</th>";

                echo "<th style='border: 1px solid #ddd; padding: 8px;'>Email</th>";

            <div class="form-group">    echo "<th style='border: 1px solid #ddd; padding: 8px;'>Subject</th>";

                <label for="phone">Phone Number</label>    echo "<th style='border: 1px solid #ddd; padding: 8px;'>Date</th>";

                <input type="tel" id="phone" name="phone"     echo "</tr>";

                       value="<?php echo isset($_POST['phone']) ? htmlspecialchars($_POST['phone']) : '9876543210'; ?>">    

            </div>    while ($row = mysqli_fetch_assoc($result)) {

                    echo "<tr>";

            <div class="form-group">        echo "<td style='border: 1px solid #ddd; padding: 8px;'>" . htmlspecialchars($row['name']) . "</td>";

                <label for="subject">Subject *</label>        echo "<td style='border: 1px solid #ddd; padding: 8px;'>" . htmlspecialchars($row['email']) . "</td>";

                <select id="subject" name="subject" required>        echo "<td style='border: 1px solid #ddd; padding: 8px;'>" . htmlspecialchars($row['subject']) . "</td>";

                    <option value="">Select Subject</option>        echo "<td style='border: 1px solid #ddd; padding: 8px;'>" . $row['created_at'] . "</td>";

                    <option value="general" <?php echo (isset($_POST['subject']) && $_POST['subject'] == 'general') ? 'selected' : ''; ?>>General Inquiry</option>        echo "</tr>";

                    <option value="support" <?php echo (isset($_POST['subject']) && $_POST['subject'] == 'support') ? 'selected' : ''; ?>>Technical Support</option>    }

                    <option value="payment" <?php echo (isset($_POST['subject']) && $_POST['subject'] == 'payment') ? 'selected' : ''; ?>>Payment Issue</option>    echo "</table>";

                    <option value="account" <?php echo (isset($_POST['subject']) && $_POST['subject'] == 'account') ? 'selected' : ''; ?>>Account Related</option>} else {

                    <option value="feedback" <?php echo (isset($_POST['subject']) && $_POST['subject'] == 'feedback') ? 'selected' : ''; ?>>Feedback</option>    echo "<p>No contacts found in database yet.</p>";

                </select>}

            </div>

            echo "<br><br><a href='contact.php' style='background: #17a2b8; color: white; padding: 10px 20px; text-decoration: none; border-radius: 5px;'>← Back to Contact Form</a>";

            <div class="form-group">?>
                <label for="message">Message *</label>
                <textarea id="message" name="message" rows="5" required><?php echo isset($_POST['message']) ? htmlspecialchars($_POST['message']) : 'This is a test message for contact form debugging.'; ?></textarea>
            </div>
            
            <button type="submit">Send Test Message</button>
        </form>
        
        <div style="margin-top: 30px; padding: 20px; background: #f8f9fa; border-radius: 5px;">
            <h3>Testing Instructions:</h3>
            <ol>
                <li>Fill out the form with test data (pre-filled)</li>
                <li>Submit the form to test database insertion</li>
                <li>Check for any error messages</li>
                <li>Verify data appears in admin dashboard</li>
                <li>Test WhatsApp notification functionality</li>
            </ol>
            
            <h4>Common Issues to Check:</h4>
            <ul>
                <li>Database connection errors</li>
                <li>Missing contacts table</li>
                <li>PHP errors in form processing</li>
                <li>WhatsApp API configuration</li>
                <li>Email sending functionality</li>
            </ul>
        </div>
    </div>
</body>
</html>