-
Notifications
You must be signed in to change notification settings - Fork 0
/
process_expert_form.php
66 lines (54 loc) · 2.09 KB
/
process_expert_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
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
<?php
$servername = "localhost";
$username = "root";
$password = "";
$database = "user_management";
// Create connection
$conn = new mysqli($servername, $username, $password, $database);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Function to sanitize user input
function sanitizeInput($input) {
global $conn;
$input = trim($input);
$input = stripslashes($input);
$input = htmlspecialchars($input);
return $conn->real_escape_string($input);
}
// Function to validate email
function validateEmail($email) {
return filter_var($email, FILTER_VALIDATE_EMAIL);
}
if ($_SERVER["REQUEST_METHOD"] === "POST") {
// Validate and sanitize form data
$full_name = sanitizeInput($_POST["full_name"]);
$email = sanitizeInput($_POST["email"]);
$phone_number = sanitizeInput($_POST["phone_num"]);
$location = sanitizeInput($_POST["location"]);
$profession = sanitizeInput($_POST["profession"]);
$services = isset($_POST["services"]) ? sanitizeInput($_POST["services"]) : ''; // Validate and sanitize services
$about = sanitizeInput($_POST["about"]);
// Check if services field is not empty
if (empty($services)) {
echo "Error: Services field cannot be empty.";
} else {
// Insert data into the 'experts' table
$sql = "INSERT INTO expert (full_name, email, phone_number, location, profession, services, about)
VALUES (?, ?, ?, ?, ?, ?, ?)";
// Prepare and bind the parameters
$stmt = $conn->prepare($sql);
$stmt->bind_param("sssssss", $full_name, $email, $phone_number, $location, $profession, $services, $about);
if ($stmt->execute()) {
echo '<script>alert("Expert registration successful."); window.location.href = "index.php";</script>';
} else {
echo "Error: " . $stmt->error;
}
// Close the prepared statement
$stmt->close();
}
// Close the database connection
$conn->close();
}
?>