forked from if-itb/IF3110-01-Simple-Blog
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathupdate_comment.php
More file actions
36 lines (27 loc) · 1.07 KB
/
update_comment.php
File metadata and controls
36 lines (27 loc) · 1.07 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
<?php
$data = json_decode(file_get_contents('php://input'));
// postID, name, email, content
if (!(isset($data->{'postID'}) && isset($data->{'name'}) && isset($data->{'email'})
&& isset($data->{'content'}))) {
echo "Failed, Wrong POST";
} else {
$mysqli = new mysqli("localhost", "WBD_USER", "QKC3zwhJ", "WBD_DB");
if ($mysqli->connect_errno) {
echo "Failed to connect to MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error;
} else {
if (!($stmt = $mysqli->prepare("INSERT INTO `comments`(`ID_POST`, `NAME`, `EMAIL`, `COMMENT`) VALUES (?, ?, ?, ?)"))) {
echo "Prepare failed: (" . $mysqli->errno . ") " > $mysqli->error;
} else {
if (!$stmt->bind_param("isss", $data->{'postID'}, $data->{'name'}, $data->{'email'}, $data->{'content'})) {
echo "Binding parameters failed: (" . $stmt->errno . ") " . $stmt->error;
} else {
if (!$stmt->execute()) {
echo "Execute failed: (" . $stmt->errno . ") " . $stmt->error;
} else {
echo "SUCCESS";
}
}
}
}
}
?>