skip to Main Content

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


  1. Chosen as BEST ANSWER
    <?php
    if (isset($_POST['delete'])) {
        $SQLSelect = $odb->query("DELETE FROM `accounts_free` ORDER BY `id` ASC LIMIT 1");
        
    }
    
    ?>
    

    Thats worked for me.


  2. 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:

    <input type="hidden" name="accounts_free_id" value="ACCOUT_FREE_ID_TO_DELETE">
    

    And inside your if:

    //space removed as @arkascha suggested
    $SQL = $odb->prepare("DELETE FROM `accounts_free` WHERE `id`='.$_POST['accounts_free_id'].'");
    

    In this example I suppose the identifier of accounts_free table is id. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search