-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_skill.php
More file actions
51 lines (42 loc) · 1.6 KB
/
add_skill.php
File metadata and controls
51 lines (42 loc) · 1.6 KB
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
<?php
session_start();
include("includes/db_connect.php");
if (!isset($_SESSION["user_id"])) {
header("Location: auth/login.php");
exit();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$user_id = $_SESSION["user_id"];
$skill_type = trim($_POST["skill_type"] ?? '');
$skill_name = trim($_POST["skill_name"] ?? '');
$description = trim($_POST["description"] ?? '');
$location = trim($_POST["location"] ?? '');
// Validation
if (empty($skill_name) || empty($description) || empty($skill_type) || empty($location)) {
header("Location: skills.php?error=All fields including location are required.");
exit();
}
// ✅ Capitalize each word before saving
$skill_name = ucwords(strtolower($skill_name));
$description = ucfirst($description);
$location = ucwords(strtolower($location));
$stmt = $conn->prepare("
INSERT INTO skills (user_id, skill_type, skill_name, description, location)
VALUES (?, ?, ?, ?, ?)
");
if ($stmt === false) {
error_log("Prepare failed: " . $conn->error);
header("Location: skills.php?error=Internal error. Try again.");
exit();
}
$stmt->bind_param("issss", $user_id, $skill_type, $skill_name, $description, $location);
if ($stmt->execute()) {
header("Location: index.php?success=Skill added successfully!");
} else {
error_log("Database error in add_skill.php: " . $conn->error);
header("Location: skills.php?error=Failed to add skill. Try again.");
}
$stmt->close();
exit();
}
?>