-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprocess_form.php
More file actions
40 lines (34 loc) · 1.09 KB
/
process_form.php
File metadata and controls
40 lines (34 loc) · 1.09 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
36
37
38
39
40
<?php
// Database connection details
$host = 'localhost';
$username = 'root';
$password = '';
$dbname = 'edtech';
// Create a connection
$conn = new mysqli($host, $username, $password, $dbname);
// Check the connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Retrieve form data
$name = $conn->real_escape_string($_POST['name']);
$email = $conn->real_escape_string($_POST['email']);
$message = $conn->real_escape_string($_POST['message']);
// Insert the data into the database
$sql = "INSERT INTO messages (name, email, message) VALUES ('$name', '$email', '$message')";
if ($conn->query($sql) === TRUE) {
echo "<script>
alert('Message sent successfully!');
window.location.href = 'index.php';
</script>";
} else {
echo "<script>
alert('Error: " . $conn->error . "');
window.location.href = 'index.php';
</script>";
}
}
// Close the connection
$conn->close();
?>