-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathread.php
More file actions
42 lines (31 loc) · 934 Bytes
/
read.php
File metadata and controls
42 lines (31 loc) · 934 Bytes
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
<?php
include 'dbconnection.php';
$id = filter_var($_GET['id'], FILTER_SANITIZE_STRING);
$status = [
"status" => "success",
"notes" => [],
];
try{
$sql = "SELECT * FROM notes WHERE id=:id";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_STR);
$id = $id;
$stmt->execute();
$notes = $stmt->fetchAll();
if (count($notes) > 0) {
foreach ($notes as $note) {
array_push($status['notes'], [
'id' => $note['id'],
'title' => $note['title'],
'author' => $note['author'],
'messages' => $note['messages'],
]);
}
} else {
$status['status'] = "error";
$status['message'] = "no note found with this id";
}
echo json_encode($status);
} catch(PDOException $e){
die("ERROR: Could not prepare/execute query: $sql. " . $e->getmessages());
}