-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcontact.php
26 lines (21 loc) · 885 Bytes
/
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
<?php
// Include the database connection file
include 'include/config.php';
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve form data
$name = isset($_POST['name']) ? $_POST['name'] : '';
$email = isset($_POST['email']) ? $_POST['email'] : '';
$message = isset($_POST['message']) ? $_POST['message'] : '';
// Insert data into the database
$sql = "INSERT INTO messages (person_name, person_mail,person_message) VALUES ('$name', '$email', '$message')";
if ($con->query($sql) === TRUE) {
echo "<script>alert('Message sent successfully!');</script>";
echo "<script>window.history.back();</script>"; // Redirect to the previous page
exit; // Stop further execution
} else {
echo "Error: " . $sql . "<br>" . mysqli_error($con);
}
}
// Close database connection
$con->close();