-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsecond_request.php
More file actions
70 lines (60 loc) · 2.24 KB
/
Copy pathsecond_request.php
File metadata and controls
70 lines (60 loc) · 2.24 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
<?php
session_start();
include 'includes/db_connect.php';
if (!isset($_SESSION['user_id'])) {
header("Location: auth/login.php");
exit();
}
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$requester_id = $_SESSION['user_id'];
$provider_id = $_POST['provider_id'] ?? null;
$provider_skill_id = $_POST['provider_skill_id'] ?? null;
$offered_price = $_POST['offered_price'] ?? 0;
if (!$provider_id || !$provider_skill_id) {
die("Error: Missing provider_id or provider_skill_id.");
}
// Fetch the provider's skill id (to store in the request)
$stmt = $conn->prepare("SELECT id FROM skills WHERE user_id = ? AND id = ?");
$stmt->bind_param("ii", $provider_id, $provider_skill_id);
$stmt->execute();
$stmt->bind_result($skill_id);
$stmt->fetch();
$stmt->close();
if (!$skill_id) {
die("Error: Invalid skill.");
}
// Check if a similar request already exists (not cancelled)
$check = $conn->prepare("
SELECT id FROM requests
WHERE requester_id = ?
AND provider_id = ?
AND skill_id = ?
AND status != 'Cancelled'
");
$check->bind_param("iii", $requester_id, $provider_id, $skill_id);
$check->execute();
$result = $check->get_result();
if ($result->num_rows > 0) {
// ✅ Show green alert message on index.php instead of popup
$_SESSION['message'] = "You already have an active request for this skill.";
$_SESSION['message_type'] = "info";
header("Location: index.php");
exit();
}
// Insert request (with offered price and skill id)
$query = "INSERT INTO requests (requester_id, provider_id, skill_id, offered_price, status, created_at)
VALUES (?, ?, ?, ?, 'pending', NOW())";
$stmt = $conn->prepare($query);
$stmt->bind_param("iiid", $requester_id, $provider_id, $skill_id, $offered_price);
if ($stmt->execute()) {
$_SESSION['message'] = "Request sent successfully!";
$_SESSION['message_type'] = "success";
header("Location: requests_sent.php");
exit();
} else {
echo "Error: " . $stmt->error;
}
$stmt->close();
}
$conn->close();
?>