-
Notifications
You must be signed in to change notification settings - Fork 0
/
contact.php
40 lines (33 loc) · 1.28 KB
/
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
32
33
34
35
36
37
38
39
40
<?php
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$name = $_POST["name"];
$email = $_POST["email"];
$number = $_POST["number"];
$subject = $_POST["subject"];
$message = $_POST["message"];
$conn = mysqli_connect("localhost", "root","");
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
mysqli_select_db($conn, "dottech");
$stmt = $conn->prepare("INSERT INTO contact (name, email, number, subject, message) VALUES (?, ?, ?, ?, ?)");
$stmt->bind_param("sssss", $name, $email, $number, $subject, $message);
// Execute the prepared statement
if ($stmt->execute()) {
//echo "Record inserted successfully";
$response = array("status" => "success", "message" => "Your message has been sent. Thank you!");
} else {
// echo "Error: " . $stmt->error;
$response = array("status" => "error", "message" => "Error inserting record");
}
header("Content-Type: application/json");
echo json_encode($response);
$stmt->close();
mysqli_close($conn);
}
else {
header("HTTP/1.1 405 Method Not Allowed");
header("Allow: POST");
echo "Method not allowed";
}
?>