From 7d452c27242257ae0842fa9428907f395c8c5fcc Mon Sep 17 00:00:00 2001 From: SlaVIc31 Date: Wed, 28 Mar 2018 22:13:26 +0200 Subject: [PATCH 1/3] Confirm delete Potwierdzenie przy usuwaniu rekordu i zmiana 'include' na 'require'. --- index.php | 4 ++-- modules/categories.php | 4 +--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/index.php b/index.php index 67a3265..f1df7ae 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,6 @@ - @@ -25,9 +24,8 @@ Edit - Delete + Delete - \ No newline at end of file From 94f0530114f9e21864c7deef65b0d24c5137d071 Mon Sep 17 00:00:00 2001 From: SlaVIc31 Date: Wed, 28 Mar 2018 23:39:45 +0200 Subject: [PATCH 2/3] Update categories.php --- modules/categories.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/categories.php b/modules/categories.php index 2723c87..ddb9abf 100644 --- a/modules/categories.php +++ b/modules/categories.php @@ -24,8 +24,8 @@ Edit - Delete + Delete - \ No newline at end of file + From c5a8726542a74a1912eb7e98eeaa3078ead1e297 Mon Sep 17 00:00:00 2001 From: SlaVIc31 Date: Thu, 29 Mar 2018 13:53:18 +0200 Subject: [PATCH 3/3] Checking if the id is in the database --- addons/check_id_in_db.php | 12 ++++++++++++ index.php | 1 + modules/delete_category.php | 15 ++++++++------- modules/edit_category.php | 13 +++++++------ 4 files changed, 28 insertions(+), 13 deletions(-) create mode 100644 addons/check_id_in_db.php diff --git a/addons/check_id_in_db.php b/addons/check_id_in_db.php new file mode 100644 index 0000000..24f0e56 --- /dev/null +++ b/addons/check_id_in_db.php @@ -0,0 +1,12 @@ +prepare('SELECT id FROM categories'); +$result->execute(); +$checkId = $result->fetchAll(); + +$id_array = array(); + +foreach($checkId as $id_in_database) +{ + array_push($id_array, $id_in_database['id']); +} \ No newline at end of file diff --git a/index.php b/index.php index f1df7ae..1b8b442 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,7 @@ prepare('DELETE FROM categories WHERE id = :id'); -$result->bindParam(':id', $_GET['id']); -$result->execute(); -header('location: index.php?v=categories'); \ No newline at end of file +if(!isset($_GET['id']) || !in_array($_GET['id'], $id_array)) { + header('location: index.php?v=categories'); +}else{ + $result = $pdo->prepare('DELETE FROM categories WHERE id = :id'); + $result->bindParam(':id', $_GET['id']); + $result->execute(); + header('location: index.php?v=categories'); +} \ No newline at end of file diff --git a/modules/edit_category.php b/modules/edit_category.php index c992f28..95a4fc0 100644 --- a/modules/edit_category.php +++ b/modules/edit_category.php @@ -9,14 +9,15 @@ header('location: index.php?v=categories'); } -if(!isset($_GET['id'])) { - header('location: index.php?v=categories'); +if(!isset($_GET['id']) || !in_array($_GET['id'], $id_array )) { + header('location: index.php?v=categories'); +}else{ + $result = $pdo->prepare('SELECT * FROM categories WHERE id = :id'); + $result->bindParam(':id', $_GET['id']); + $result->execute(); + $category = $result->fetch(); } -$result = $pdo->prepare('SELECT * FROM categories WHERE id = :id'); -$result->bindParam(':id', $_GET['id']); -$result->execute(); -$category = $result->fetch(); ?>