-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathprocess_postComment.php
More file actions
43 lines (41 loc) · 1.35 KB
/
Copy pathprocess_postComment.php
File metadata and controls
43 lines (41 loc) · 1.35 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
32
33
34
35
36
37
38
39
40
41
42
43
<?php
/**
* Created by PhpStorm.
* User: louis
* Date: 5/4/17
* Time: 4:30 PM
*/
session_start();
require_once ('include/dbconfig.php');
require_once ('include/helpfulFunctions.php');
require_once('include/header.php');
$username = $_SESSION['username'];
$pid = $_POST['pid'];
$pdo = db_connect();
$stmt = $pdo -> prepare(
"insert into Discussion (username, pid, aComment) values (:username, :pid, :aComment)"
);
$stmt -> bindParam(":username", $_SESSION['username'], PDO::PARAM_STR);
$stmt -> bindParam(":pid", $pid, PDO::PARAM_STR);
$stmt -> bindParam(":aComment", $_POST['aComment'], PDO::PARAM_STR);
try {
$result = $stmt->execute();
} catch (Exception $e) {
warningMessage($e -> getMessage());
}
if (isset($result)) {
$log = $pdo -> prepare(
"insert into log(username, operation, target)
values (:username, :operation, :target)"
);
$operation = "comment";
$log -> bindParam(":username", $username, $pdo::PARAM_STR);
$log -> bindParam(":operation", $operation, $pdo::PARAM_STR);
$log -> bindParam(":target", $pid, $pdo::PARAM_INT);
$log -> execute();
correctMessage("Add comment successfully, redirecting to project page...");
echo "<meta http-equiv='refresh' content='2; url=project.php?pid=$pid'>";
} else {
warningMessage("Unable to add comment");
}
require_once ('include/footer.html');