-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit_contact.php
More file actions
34 lines (30 loc) · 1.12 KB
/
submit_contact.php
File metadata and controls
34 lines (30 loc) · 1.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
<?php
require 'dbContact.php'; // Connect to the database
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Sanitize input data
$name = filter_var($_POST['name'], FILTER_SANITIZE_STRING);
$phone = filter_var($_POST['phone'], FILTER_SANITIZE_STRING);
$email = filter_var($_POST['email'], FILTER_SANITIZE_EMAIL);
$field = $_POST['field'];
$message = filter_var($_POST['message'], FILTER_SANITIZE_STRING);
// Validate email format
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
die("Invalid email format.");
}
try {
// Insert data into the database
$stmt = $pdo_contact->prepare("INSERT INTO contact_messages (name, phone, email, field, message)
VALUES (:name, :phone, :email, :field, :message)");
$stmt->execute([
'name' => $name,
'phone' => $phone,
'email' => $email,
'field' => $field,
'message' => $message
]);
echo "Thank you! Your message has been submitted.";
} catch (PDOException $e) {
echo "Error: " . $e->getMessage();
}
}
?>