-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrequest_skill.php
More file actions
81 lines (73 loc) · 2.83 KB
/
Copy pathrequest_skill.php
File metadata and controls
81 lines (73 loc) · 2.83 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
<?php
session_start();
include 'includes/db_connect.php'; // ✅ Ensure your DB connection file is included
// Redirect to login if not logged in
if (!isset($_SESSION['user_id'])) {
header("Location: auth/login.php");
exit();
}
$requester_id = $_SESSION['user_id']; // Logged-in user
$provider_id = $_GET['provider_id'] ?? null;
$provider_skill_id = $_GET['provider_skill_id'] ?? null;
// ✅ Step 1: Check if all data is available
if (!$provider_id || !$provider_skill_id) {
die("Invalid request — missing data.");
}
// ✅ Step 2: Show a form to choose which of the user's skills to offer
if ($_SERVER["REQUEST_METHOD"] != "POST") {
// Fetch user's own skills to choose one
$stmt = $conn->prepare("SELECT id, title FROM skills WHERE user_id = ?");
$stmt->bind_param("i", $requester_id);
$stmt->execute();
$skills = $stmt->get_result()->fetch_all(MYSQLI_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Send Skill Request</title>
<link rel="stylesheet" href="assets/css/style.css">
<style>
body { font-family: Arial; background: #f8f9fa; padding: 30px; }
form {
background: white; padding: 20px; border-radius: 12px;
box-shadow: 0 3px 10px rgba(0,0,0,0.1); width: 350px;
}
select, button { width: 100%; padding: 8px; margin-top: 10px; }
button { background: #06d6a0; color: white; border: none; border-radius: 6px; cursor: pointer; }
button:hover { background: #05b589; }
</style>
</head>
<body>
<h2>Request This Skill</h2>
<form method="POST">
<label for="requester_skill_id">Choose one of your skills to offer in exchange:</label>
<select name="requester_skill_id" required>
<option value="">-- Select your skill --</option>
<?php foreach ($skills as $skill): ?>
<option value="<?php echo $skill['id']; ?>"><?php echo htmlspecialchars($skill['title']); ?></option>
<?php endforeach; ?>
</select>
<button type="submit">Send Request</button>
</form>
</body>
</html>
<?php
exit();
}
// ✅ Step 3: Handle form submission
$requester_skill_id = $_POST['requester_skill_id'];
$stmt = $conn->prepare("
INSERT INTO requests (requester_id, provider_id, requester_skill_id, provider_skill_id)
VALUES (?, ?, ?, ?)
");
$stmt->bind_param("iiii", $requester_id, $provider_id, $requester_skill_id, $provider_skill_id);
if ($stmt->execute()) {
echo "<script>
alert('Swap Request sent successfully!');
window.location.href='dashboard.php';
</script>";
} else {
echo "Error: " . $conn->error;
}
?>