-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathcommented.php
52 lines (41 loc) · 1.21 KB
/
commented.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
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
//start session
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns = "http://www.w3.org/1999/xhtml">
<head>
<link rel="stylesheet" type="text/css" href="mystyle.css"></link>
<title>Commented</title>
</head>
<body class="infoPage">
<?php
include_once("config.php");
// Open database connection
$conn = mysqli_connect(DB_HOST_NAME, DB_USER, DB_PASS, DB_NAME);
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$pid = $_POST["thePostId"];
$uid = $_SESSION['login_user'];
$content = htmlspecialchars(addslashes(trim($_POST["comment1"])));
$date = date('Y/m/d H:i:s', time());
$sql = "INSERT INTO Comments (parentPostId, timestamp, creatorId, text)
VALUES ('$pid', '$date', '$uid', '$content');";
//upload comment to database
if (mysqli_query($conn, $sql)) {
echo "<br/>Comment successful!<br/>Redirecting...";
} else { // if failed to add a new record:
echo "<br/>Comment failed<br/>Redirecting...";
}
// close database connection
mysqli_close($conn);
//redirect
echo ' <META HTTP-EQUIV="Refresh" Content="2; URL=comment.php?a=';
echo $_POST["thePostId"];
echo '">';
exit();
?>
</body>
</html>