-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprocess_form.php
34 lines (28 loc) · 912 Bytes
/
process_form.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
31
32
33
34
<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "contact_form_db";
// Create a connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Process form submission
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["Name"];
$email = $_POST["Email"];
$subject = $_POST["Subject"];
$message = $_POST["Message"];
// Insert data into the table
$sql = "INSERT INTO form_submissions (name, email, subject, message) VALUES ('$name', '$email', '$subject', '$message')";
if ($conn->query($sql) === TRUE) {
echo "Thank you for contacting us. We will get back to you soon.";
} else {
echo "Oops! Something went wrong. Please try again later.";
}
}
// Close the database connection
$conn->close();
?>