-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathsubmit_contact.php
More file actions
35 lines (31 loc) · 1.01 KB
/
submit_contact.php
File metadata and controls
35 lines (31 loc) · 1.01 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
35
<?php
require_once __DIR__ . '/config/db.php';
require_once __DIR__ . '/config/security.php';
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
header('Location: contact.php');
exit;
}
$name = sanitizeInput($_POST['name'] ?? '');
$emailValidation = validateEmail($_POST['email'] ?? '');
if (!$emailValidation['valid']) {
header('Location: contact.php?error=1');
exit;
}
$email = $emailValidation['email'];
$subject = sanitizeInput($_POST['subject'] ?? '');
$messageValidation = validateText($_POST['message'] ?? '', 1, 1000);
if (!$messageValidation['valid']) {
header('Location: contact.php?error=1');
exit;
}
$message = $messageValidation['text'];
$conn = nearby_db_connect();
$sql = "INSERT INTO contact (name, email, subject, message) VALUES (?, ?, ?, ?)";
$stmt = mysqli_prepare($conn, $sql);
mysqli_stmt_bind_param($stmt, 'ssss', $name, $email, $subject, $message);
if (mysqli_stmt_execute($stmt)) {
header('Location: contact.php?success=1');
} else {
header('Location: contact.php?error=1');
}
exit;