saverating.php 1.14 KB
Newer Older
root's avatar
root committed
1
<?php
2 3 4 5 6 7 8 9 10 11

// Required parameters.
($_username = $_POST['username'] ?? null) || die('no username given');
($_userurl = $_POST['userurl'] ?? null) || die('no userurl given');
($_domain = $_POST['domain'] ?? null) || die('no pod domain given');
($_comment = $_POST['comment'] ?? null) || die('no comment');
($_rating = $_POST['rating'] ?? null) || die('no rating given');

// Other parameters.
$_email = $_POST['email'] ?? '';
12 13 14

require_once __DIR__ . '/../config.php';

dmorley's avatar
dmorley committed
15
$dbh = pg_connect("dbname=$pgdb user=$pguser password=$pgpass");
16 17
$dbh || die('Error in connection: ' . pg_last_error());

18 19
$sql    = 'INSERT INTO rating_comments (domain, comment, rating, username, userurl) VALUES($1, $2, $3, $4, $5)';
$result = pg_query_params($dbh, $sql, [$_domain, $_comment, $_rating, $_username, $_userurl]);
20 21
$result || die('Error in SQL query: ' . pg_last_error());

22
$to      = $adminemail;
23
$subject = 'New rating added to poduptime ';
24 25
$message = 'Pod:' . $_domain . $_domain . $_username . $_userurl . $_comment . $_rating . "\n\n";
$headers = 'From: ' . $_email . "\r\n";
26
@mail($to, $subject, $message, $headers);
27
echo 'Comment posted!';
28

dmorley's avatar
dmorley committed
29 30
pg_free_result($result);
pg_close($dbh);