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 67a3265..1b8b442 100644 --- a/index.php +++ b/index.php @@ -1,6 +1,7 @@ - @@ -25,9 +24,8 @@ Edit - Delete + Delete - - \ No newline at end of file + diff --git a/modules/delete_category.php b/modules/delete_category.php index a388f34..d48c576 100644 --- a/modules/delete_category.php +++ b/modules/delete_category.php @@ -1,9 +1,10 @@ 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(); ?>