Answer the question
In order to leave comments, you need to log in
How to set up a button to delete a record from the database?
Essence of a question: it is necessary to drink the button for removal of record from a DB. We have the form:
<form class="lot-item__form" action="../lot.php?id=<?=$id;?>" method="post">
<?php $classname = isset($error['com']) ? "--invalid" : "";?>
<p class="lot-item__form-item <?=$classname;?>">
<label for="com">Ваш комментарий</label>
<textarea name="com" id="com" cols="33" rows="8"></textarea>
<button type="submit" class="button">Комментировать</button>
<button type="submit" name="del" class="button">Удалить пост</button>
</p>
</form>
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
if (isset($_POST['del'])) {
$sql = 'DELETE * FROM post WHERE id = "' .$id. '";';
$res = mysqli_query ($con, $sql);
}
}
Answer the question
In order to leave comments, you need to log in
I'm not strong in PHP, but suddenly I thought that it would be no ice if some well-wisher gives you a string like this: 1235" + "or 1=1" + "as an id. IMHO, it would be necessary to patch it somehow ...
It's a bad idea to delete something completely.
Perhaps it makes more sense to make the article inactive? THOSE. by pressing a button in some table of the
ID_article format | Active
for the article will be set to, for example, 0 and the article will no longer be displayed in the feed, but it will be saved in the database and in which case it can always be restored
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question