-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsubmit_contact.php
31 lines (25 loc) · 1.02 KB
/
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
31
<?php
// Establish database connection
$servername = "localhost"; // Change if your MySQL server is running on a different host
$username = "root"; // Default username for MySQL
$password = ""; // Default password for MySQL
$dbname = "test1"; // Replace 'your_database_name' with your actual database name
// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Retrieve form data and sanitize it
$name = mysqli_real_escape_string($conn, $_POST['name']);
$email = mysqli_real_escape_string($conn, $_POST['email']);
$message = mysqli_real_escape_string($conn, $_POST['message']);
// Insert form data into database
$sql = "INSERT INTO contacts (name, email, message) VALUES ('$name', '$email', '$message')";
if ($conn->query($sql) === TRUE) {
echo "New record created successfully";
} else {
echo "Error: " . $sql . "<br>" . $conn->error;
}
$conn->close();
?>