-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsubmit_feedback.php
More file actions
31 lines (28 loc) · 1.14 KB
/
submit_feedback.php
File metadata and controls
31 lines (28 loc) · 1.14 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
<?php
session_start();
require_once 'config.php';
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
$user_id = $_SESSION['user_id'] ?? 0;
$booking_id = intval($_POST['booking_id']);
$rating = intval($_POST['rating']);
$comment = trim($_POST['comment']);
// Fetch service name
$stmt = $conn->prepare("SELECT service_name FROM bookings WHERE booking_id = ? AND user_id = ?");
$stmt->bind_param("ii", $booking_id, $user_id);
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_assoc();
$service_name = $row['service_name'] ?? '';
if ($service_name) {
$insert = $conn->prepare("INSERT INTO feedback (booking_id, user_id, service_name, rating, comment) VALUES (?, ?, ?, ?, ?)");
$insert->bind_param("iisds", $booking_id, $user_id, $service_name, $rating, $comment);
if ($insert->execute()) {
echo json_encode(["status" => "success"]);
} else {
echo json_encode(["status" => "error", "message" => "Database insertion failed"]);
}
} else {
echo json_encode(["status" => "error", "message" => "Invalid booking or user"]);
}
}
?>