-
Notifications
You must be signed in to change notification settings - Fork 124
/
Copy pathinsertratings.php
39 lines (31 loc) · 1.2 KB
/
insertratings.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
39
<?php
// Populate using direct DB access
if ( empty($_SESSION['DBHOST']) ) { return; }
$mysql_hostname = $_SESSION['DBHOST'];
$mysql_port = $_SESSION['DBPORT'];
$mysql_username = $_SESSION['DBUSER'];
$mysql_dbname = $_SESSION['DBNAME'];
$mysql_password = $_SESSION['DBPASSWORD'];
try {
$dbh = new PDO("mysql:host=$mysql_hostname;port=$mysql_port;dbname=$mysql_dbname", $mysql_username, $mysql_password);
$dbh -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$stmt = $dbh -> prepare("
INSERT INTO ratings (sessionid, theme, name, rating)
VALUES (:sessionid, :theme, :name, :rating);
;");
$sessionid = session_id();
$theme = $_SESSION['SELECTOR'];
$name = $_SESSION['name'];
$rating = $_SESSION['rating'];
$stmt -> bindParam(':sessionid', $sessionid, PDO::PARAM_STR, 40);
$stmt -> bindParam(':theme', $theme, PDO::PARAM_STR, 40);
$stmt -> bindParam(':name', $name, PDO::PARAM_STR, 40);
$stmt -> bindParam(':rating', $rating, PDO::PARAM_STR, 40);
$stmt -> execute();
$count = $stmt -> rowCount();
} catch(Exception $e) {
$_SESSION['message'] = 'We are unable to save your rating. Please try again later. '.$e;
header("Location: /error.php");
die();
}
?>