im tring to delete first row in phpmyadmin but i have problem. i dont get any SQL error.
PHP codes
if (isset($_POST['delete'])) {
echo "deleted";
$delete = $_POST['delete'];
$SQL = $odb -> prepare("DELETE FROM `accounts_free`LIMIT 1");
$SQL -> execute(array($delete));
$notify = success('Account has been successfully deleted');
}
html
<form method="post">
<button name="delete" value="test" type="submit" class="btn btn-outline-danger"><i class="far fa-trash-alt"></i></button>
</form>
another button
<form method="post">
<button name="delete" class="btn btn-hero-success js-click-ripple-enabled" type="submit" data-toggle="click-ripple" style="margin-right:auto;margin-left:auto;overflow: hidden; position: relative; z-index: 1;">test</button>
</form>
i didnt find any solutions.
im not sure whats wrong. can you help me?
in different page this codes are working
php
if (isset($_POST['delete'])) {
$delete = $_POST['delete'];
$SQL = $odb -> prepare("DELETE FROM `accounts_free` WHERE `id` = ?");
$SQL -> execute(array($delete));
$notify = success('Account has been successfully deleted');
}
html
<button name="delete" value="<?=$rAccount['id']?>" type="submit" class="btn btn-outline-danger"><i class="far fa-trash-alt"></i></button>
2
Answers
Thats worked for me.
First of all it seems to me that this is not PhpMyAdmin but your own PHP code. Second, as @ADyson and @arkascha suggested, you will want to specify which row to delete possibly using the row primary key. For example, you can add this inside your
<form>
tags:And inside your
if
:In this example I suppose the identifier of
accounts_free
table isid
. This is only to give you the idea: remember that every input that arrives from the outside has to be checked to avoid SQL Injection or other kinds of attack attempts.