-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit_contact.php
30 lines (24 loc) · 982 Bytes
/
submit_contact.php
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
<?php
include 'database.php';
// Validate and sanitize input
$name = filter_input(INPUT_POST, 'name', FILTER_SANITIZE_STRING);
$email = filter_input(INPUT_POST, 'email', FILTER_SANITIZE_EMAIL);
$message = filter_input(INPUT_POST, 'message', FILTER_SANITIZE_STRING);
// Basic validation
if (empty($name) || empty($email) || !filter_var($email, FILTER_VALIDATE_EMAIL) || empty($message)) {
// Handle error - for example, redirect back with an error message
echo "Invalid input"; // Consider a more sophisticated error handling
} else {
// Prepared statement to insert data
$stmt = $conn->prepare("INSERT INTO contacts (name, email, message) VALUES (?, ?, ?)");
$stmt->bind_param("sss", $name, $email, $message);
if ($stmt->execute()) {
echo "Record added successfully";
// Redirect or show a success message
} else {
echo "Error: " . $stmt->error;
}
$stmt->close();
}
$conn->close();
?>