-
Notifications
You must be signed in to change notification settings - Fork 0
/
submit_rating.php
38 lines (32 loc) · 1.12 KB
/
submit_rating.php
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
<?php
session_start(); // Start the session
require('admin/inc/db_config.php');
// Define the redirect function if it doesn't exist
if (!function_exists('redirect')) {
function redirect($url) {
header("Location: $url");
exit;
}
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (!isset($_SESSION['uId'])) {
die('User not logged in. Please log in to submit a rating.');
}
$user_id = $_SESSION['uId'];
$data = filteration($_POST);
$query = "INSERT INTO rating_review (guesthouse_id, user_id, rating, review, seen, datentime)
VALUES (?, ?, ?, ?, 0, NOW())";
$params = [$data['guesthouse_id'], $user_id, $data['rating'], $data['review']];
try {
if (insert($query, $params, 'iiis')) {
redirect('guesthouses.php?success=Thank you for your feedback!');
} else {
redirect('rate_guesthouse.php?id=' . $data['guesthouse_id'] . '&error=Failed to submit feedback!');
}
} catch (Exception $e) {
die("Error: " . $e->getMessage());
}
} else {
redirect('guesthouses.php');
}
?>