/
home
/
u839856410
/
domains
/
frajuuconnect.online
/
public_html
/
Upload File
HOME
<?php // contact-agent.php session_start(); include 'db_connection.php'; if (!isset($conn)) { $conn = new mysqli("localhost", "u839856410_Frajuu", "Frajuuweb000@", "u839856410_Frajuuconnect"); if ($conn->connect_error) die("DB connect error: ".$conn->connect_error); } $success_msg = ''; $error_msg = ''; $agent_id = isset($_GET['agent_id']) ? intval($_GET['agent_id']) : 0; $property_id = isset($_GET['property_id']) ? intval($_GET['property_id']) : 0; // POST -> insert if ($_SERVER['REQUEST_METHOD'] === 'POST') { $agent_id = isset($_POST['agent_id']) ? intval($_POST['agent_id']) : 0; $property_id = isset($_POST['property_id']) ? intval($_POST['property_id']) : 0; $name = trim($_POST['name'] ?? ''); $email = trim($_POST['email'] ?? ''); $phone = trim($_POST['phone'] ?? ''); $message = trim($_POST['message'] ?? ''); if ($agent_id <= 0 || $name === '' || $email === '' || $message === '') { $error_msg = "Please fill the required fields."; } else { $stmt = $conn->prepare(" INSERT INTO messages (agent_id, property_id, name, email, phone, message, created_at) VALUES (?, ?, ?, ?, ?, ?, NOW()) "); if (!$stmt) { $error_msg = "Prepare failed: " . $conn->error; } else { $stmt->bind_param("iissss", $agent_id, $property_id, $name, $email, $phone, $message); if ($stmt->execute()) { $success_msg = "Message sent successfully to the agent."; } else { $error_msg = "Database error: " . $stmt->error; } $stmt->close(); } } } // fetch agent info if available $agent = null; if ($agent_id > 0) { $ag = $conn->prepare("SELECT id, full_name, email, phone FROM agents WHERE id = ? LIMIT 1"); if ($ag) { $ag->bind_param("i", $agent_id); $ag->execute(); $res = $ag->get_result(); if ($res && $res->num_rows === 1) $agent = $res->fetch_assoc(); $ag->close(); } } // fetch property title/location if property_id given $property = null; if ($property_id > 0) { $tables = [ 'houses_for_sale' => 'title', 'houses_for_rent' => 'title', 'plots_for_sale' => 'title', 'rooms_for_rent' => 'name' ]; foreach ($tables as $table => $title_col) { $q = $conn->prepare("SELECT id, {$title_col} AS title, location FROM {$table} WHERE id = ? LIMIT 1"); if (!$q) continue; $q->bind_param("i", $property_id); $q->execute(); $r = $q->get_result(); if ($r && $r->num_rows === 1) { $property = $r->fetch_assoc(); $q->close(); break; } $q->close(); } } ?> <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <title>Contact Agent</title> <meta name="viewport" content="width=device-width, initial-scale=1"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"> <style> /* Improve small screen readability */ .card { border-radius: 12px; } .form-control, .btn { font-size: 1rem; padding: 0.75rem; } textarea.form-control { min-height: 120px; } @media (max-width: 576px) { .card-header h3 { font-size: 1.2rem; } .form-label { font-size: 0.9rem; } .form-control, .btn { font-size: 1rem; padding: 0.85rem; } .card { margin: 0 10px; } } </style> </head> <body> <div class="container my-4"> <div class="row justify-content-center"> <div class="col-lg-6 col-md-8 col-sm-12"> <div class="card shadow-lg"> <div class="card-header bg-primary text-white text-center"> <?php if ($agent): ?> <h3 class="mb-1">Contact <?php echo htmlspecialchars($agent['full_name']); ?></h3> <small>Email: <?php echo htmlspecialchars($agent['email']); ?> | Phone: <?php echo htmlspecialchars($agent['phone']); ?></small> <?php else: ?> <h3>Contact Agent</h3> <?php endif; ?> </div> <?php if ($property): ?> <div class="card-body border-bottom bg-light mb-3"> <strong>Property:</strong> <?php echo htmlspecialchars($property['title'] . ' — ' . ($property['location'] ?? '')); ?> </div> <?php endif; ?> <div class="card-body"> <?php if ($success_msg): ?> <div class="alert alert-success"><?php echo $success_msg; ?></div> <?php endif; ?> <?php if ($error_msg): ?> <div class="alert alert-danger"><?php echo $error_msg; ?></div> <?php endif; ?> <form method="post"> <input type="hidden" name="agent_id" value="<?php echo intval($agent_id); ?>"> <input type="hidden" name="property_id" value="<?php echo intval($property_id); ?>"> <div class="mb-3"> <label class="form-label">Your Name *</label> <input type="text" name="name" class="form-control" required> </div> <div class="mb-3"> <label class="form-label">Your Email *</label> <input type="email" name="email" class="form-control" required> </div> <div class="mb-3"> <label class="form-label">Your Phone</label> <input type="text" name="phone" class="form-control"> </div> <div class="mb-3"> <label class="form-label">Message *</label> <textarea name="message" class="form-control" rows="5" required></textarea> </div> <button type="submit" class="btn btn-primary w-100">Send Message</button> </form> </div> <div class="card-footer text-center"> <a href="javascript:history.back()" class="btn btn-link">← Back</a> </div> </div> </div> </div> </div> </body> </html>