-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquote-process.php
71 lines (60 loc) · 2.12 KB
/
quote-process.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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
// Database credentials
$host = '127.0.0.1:3306'; // Change if needed
$db = 'u881526474_Services'; // Replace with your database name
$user = 'u881526474_Admin'; // Replace with your database username
$pass = 'Spiderman8085$'; // Replace with your database password
// Create connection
$conn = new mysqli($host, $user, $pass, $db);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Check if the form was submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Collect and sanitize the input data
$name = $conn->real_escape_string(trim($_POST['fname']));
$email = $conn->real_escape_string(trim($_POST['email']));
$phone = $conn->real_escape_string(trim($_POST['phone']));
$service = $conn->real_escape_string(trim($_POST['service']));
// Validate the form fields
$errors = [];
if (empty($name)) {
$errors[] = "Name is required.";
}
if (!filter_var($email, FILTER_VALIDATE_EMAIL)) {
$errors[] = "A valid email address is required.";
}
if (empty($phone)) {
$errors[] = "Phone number is required.";
}
if (empty($service)) {
$errors[] = "Please select a service.";
}
// If there are no errors, insert the data into the database
if (empty($errors)) {
$stmt = $conn->prepare("INSERT INTO quotes (name, email, phone, service) VALUES (?, ?, ?, ?)");
$stmt->bind_param("ssss", $name, $email, $phone, $service);
if ($stmt->execute()) {
// Return a success message
echo "<h3>Thank you! Your request has been submitted successfully.</h3>";
} else {
echo "Error: " . $stmt->error;
}
$stmt->close();
} else {
// If there are errors, return them
echo "<h3>There were errors with your submission:</h3>";
echo "<ul>";
foreach ($errors as $error) {
echo "<li>" . htmlspecialchars($error) . "</li>";
}
echo "</ul>";
}
}
// Close connection
$conn->close();
?>