-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsave_user.php
More file actions
34 lines (27 loc) · 878 Bytes
/
save_user.php
File metadata and controls
34 lines (27 loc) · 878 Bytes
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
<?php
require_once 'config/database.php';
try {
$conn = getDBConnection();
// Get form data
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
// Prepare SQL statement
$sql = "INSERT INTO users (first_name, last_name, email, phone) VALUES (:first_name, :last_name, :email, :phone)";
$stmt = $conn->prepare($sql);
// Bind parameters
$stmt->bindParam(':first_name', $first_name);
$stmt->bindParam(':last_name', $last_name);
$stmt->bindParam(':email', $email);
$stmt->bindParam(':phone', $phone);
// Execute the statement
$stmt->execute();
// Redirect to view users page after successful insertion
header("Location: view_users.php");
exit();
} catch(PDOException $e) {
echo "Error: " . $e->getMessage();
}
$conn = null;
?>