forked from ramsatt/A7CRUD_WEB_API
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdelete.php
32 lines (27 loc) · 927 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
<?php
header("Access-Control-Allow-Origin: *");
header("Access-Control-Allow-Methods: PUT, GET, POST");
header("Access-Control-Allow-Headers: Origin, X-Requested-With, Content-Type, Accept");
// include database connection
include 'config/database.php';
try {
// get record ID
// isset() is a PHP function used to verify if a value is there or not
$id=isset($_GET['id']) ? $_GET['id'] : die('ERROR: Record ID not found.');
// delete query
$query = "DELETE FROM products WHERE p_id = ?";
$stmt = $con->prepare($query);
$stmt->bindParam(1, $id);
if($stmt->execute()){
// redirect to read records page and
// tell the user record was deleted
echo json_encode(array('result'=>'success'));
}else{
echo json_encode(array('result'=>'fail'));
}
}
// show error
catch(PDOException $exception){
die('ERROR: ' . $exception->getMessage());
}
?>