-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.php
42 lines (30 loc) · 816 Bytes
/
delete.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
<?php
include 'dbconnection.php';
$idValue = filter_var($_GET['id'], FILTER_SANITIZE_STRING);
$status = [
"status" => "success",
];
$errors = [];
if ($idValue == "" || $idValue == null) {
$errors['id'] = "id is empty";
}
if (!is_integer((int)$idValue)) {
$errors['id'] = "id is empty";
}
if (!empty($errors)) {
$status['status'] = "error";
$status['errors'] = $errors;
echo json_encode($status);
die;
}
try{
$sql = "DELETE FROM notes WHERE id = :id";
$stmt = $pdo->prepare($sql);
$stmt->bindParam(':id', $id, PDO::PARAM_STR);
$id = $idValue;
$stmt->execute();
$status['messages'] = "note successfully deleted";
echo json_encode($status);
} catch(PDOException $e){
die("ERROR: Could not prepare/execute query: $sql. " . $e->getmessages());
}