Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions addons/check_id_in_db.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

$result = $pdo->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']);
}
5 changes: 3 additions & 2 deletions index.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<?php
include('db/pdo.php');
include('utils/utils.php');
require('db/pdo.php');
require('utils/utils.php');
require('addons/check_id_in_db.php');

if(array_key_exists('v', $_GET)) {
$module = $_GET['v'];
Expand Down
6 changes: 2 additions & 4 deletions modules/categories.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,17 +17,15 @@
<?php
foreach($categories as $category) {
?>

<tr>
<td><?php echo $category['id'];?></td>
<td><?php echo $category['name'];?></td>
<td>
<a href="index.php?v=edit_category&id=<?php echo $category['id'] ?>" class="btn btn-success">Edit</a>
</td>
<td>
<a href="index.php?v=delete_category&id=<?php echo $category['id'] ?>" class="btn btn-danger">Delete</a>
<a onclick="return confirm('Usunąć ten rekord?')" href="index.php?v=delete_category&id=<?php echo $category['id'] ?>" class="btn btn-danger">Delete</a>
</td>
</tr>

<?php } ?>
</table>
</table>
15 changes: 8 additions & 7 deletions modules/delete_category.php
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<?php
if(!isset($_GET['id'])) {
header('location: index.php?v=categories');
}

$result = $pdo->prepare('DELETE FROM categories WHERE id = :id');
$result->bindParam(':id', $_GET['id']);
$result->execute();
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('DELETE FROM categories WHERE id = :id');
$result->bindParam(':id', $_GET['id']);
$result->execute();
header('location: index.php?v=categories');
}
13 changes: 7 additions & 6 deletions modules/edit_category.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();

?>

Expand Down