added a way to delete cupboards
This commit is contained in:
parent
d7556a9edb
commit
2b9b667bdd
@ -305,7 +305,7 @@ function get_users_cupboards_array()
|
||||
$user_cupboards = array();
|
||||
|
||||
$sql = "SELECT
|
||||
id, name, description, public_id
|
||||
id, name, description, cupboards.public_id AS public_id
|
||||
FROM cupboards WHERE owner_id = :owner_id;";
|
||||
|
||||
$query = $PDO->prepare($sql);
|
||||
@ -317,3 +317,15 @@ function get_users_cupboards_array()
|
||||
}
|
||||
return $user_cupboards;
|
||||
}
|
||||
|
||||
function delete_cupboard($cupboard_public_id)
|
||||
{
|
||||
global $PDO;
|
||||
|
||||
$sql = "DELETE cupboards FROM cupboards INNER JOIN accounts ON cupboards.owner_id = accounts.id WHERE cupboards.public_id = :id;";
|
||||
$query = $PDO->prepare($sql);
|
||||
|
||||
$query->bindValue(":id", $cupboard_public_id);
|
||||
|
||||
return $query->execute();
|
||||
}
|
||||
|
@ -6,12 +6,22 @@ if (!is_connected()) {
|
||||
header("location: login.php");
|
||||
}
|
||||
|
||||
$erreur = "";
|
||||
|
||||
if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST["delete"])) {
|
||||
if (!delete_cupboard($_POST["delete"])) {
|
||||
$erreur = "<p>An item is in this cupboard, you can't delete it now.</p>\n";
|
||||
}
|
||||
}
|
||||
|
||||
$cupboard_list = "";
|
||||
foreach (get_users_cupboards_array() as $row) {
|
||||
$cupboard_list = $cupboard_list . "<tr><td>"
|
||||
. htmlspecialchars($row["name"])
|
||||
. "</td><td>"
|
||||
. htmlspecialchars($row["description"])
|
||||
. "</td><td>"
|
||||
. "<form method='post'><button type='publish' name='delete' value='" . $row["public_id"] . "'>Delete</button></form>"
|
||||
. "</td></tr>\n";
|
||||
}
|
||||
|
||||
@ -35,6 +45,7 @@ foreach (get_users_cupboards_array() as $row) {
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<?php echo $erreur; ?>
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
@ -44,6 +55,9 @@ foreach (get_users_cupboards_array() as $row) {
|
||||
<th>
|
||||
Description
|
||||
</th>
|
||||
<td>
|
||||
Supprimer
|
||||
</td>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
Loading…
Reference in New Issue
Block a user