-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditComment.php
41 lines (31 loc) · 1.13 KB
/
editComment.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
/**
*
* @var $db
*
*/
session_start();
require_once "config.php";
$stmt = $db->stmt_init();
$sql = "UPDATE CMP204comments SET content = ?, date = CURRENT_TIMESTAMP WHERE userId = {$_SESSION["id"]} AND id = ?";
if (!$stmt = $db->prepare($sql)) errorOutWithMessage("EditComment could not prepare SQL statement");
$content = $_POST["content"];
$content = $db->real_escape_string($content);
$content = htmlspecialchars($content);
$id = $_POST["id"];
$id = $db->real_escape_string($id);
$id = htmlspecialchars($id);
$stmt->bind_param("si",$content,$id);
$output = array();
if($stmt->execute()) array_push($output,"success");
else errorOut();
$stmt = $db->stmt_init();
$sql = "SELECT CMP204comments.date AS date FROM CMP204comments WHERE CMP204comments.id = {$_POST["id"]}";
if (!$stmt = $db->prepare($sql)) errorOutWithMessage("EditComment GetDateTime could not prepare SQL statement");
if($stmt->execute()) {
$result = $stmt->get_result()->fetch_assoc();
array_push($output,$_SESSION["username"]);
array_push($output,$result["date"]);
array_push($output,$content);
echo json_encode($output);
}else echo json_encode("fail");