Code to delete an individual row using a button + confirmation

This forum is a place to discuss questions about coding in the PHP programming language.
Post Reply
User avatar
Patty
New User
Posts: 3
Joined: 31 Aug 2018, 14:40

Code to delete an individual row using a button + confirmation

Post by Patty » 05 Apr 2019, 08:37

Screen Shot 2019-04-05 at 08.33.12.png
Screen Shot 2019-04-05 at 08.33.12.png (99.37 KiB) Viewed 614 times
The image above is my balance screen. What I would like to do is for the users to type confirmation then click delete and it would delete the row from the database.
My code looks something like this, I know it's a big chunk.

Code: Select all

$balance_before_transaction_query = mysqli_query($connect, 
"SELECT transaction_balance FROM transactions WHERE user_id = '$id_of_logged_in_user' ORDER BY id DESC LIMIT 1;");

while ($row1 = mysqli_fetch_array($balance_before_transaction_query)) {
    $current_balance = $row1['transaction_balance'];
}
?>


<h2> Hey <?php echo $access_control['username']; ?>, you currently have <b> <?php echo $current_balance; ?> </b> PLN</h2> 
<h2>Spendings Table</h2>
</div>                                                                      
  <div class="table-responsive">          
  <table class="table">
    <thead>
      <tr class="tablehead">
        <th>#</th>
        <th>Amount</th>
        <th>Date</th>
        <th>Category</th>
        <th>Notes</th>
        <th>Balance</th>
        <th>Delete Confirmation</th>
        <th>Delete</th>
      </tr>
    </thead>
    <tbody>
        <?php 
        
        $result = mysqli_query($connect, "SELECT * FROM transactions 
        WHERE user_id = '$id_of_logged_in_user' ORDER BY `transaction_date` DESC;");
        
        while ($row = mysqli_fetch_array($result)) {
        ?>
        <form method="POST" action="balance.php">
            <tr class="tablebody">
            <td><?php echo $row['id']; ?></td>
            <td><?php echo $row['transaction_amount']; ?></td>
            <td><?php echo $row['transaction_date']; ?></td>
            <td><?php echo $row['transaction_category'] ?></td>
            <td><?php echo $row['transaction_details']; ?></td>
            <td><?php echo $row['transaction_balance']; ?></td>
            <td><p>Type "Confirm" to Continue</p>
           <input type="text" name="inputConfirmation" required></td>
            <td><button type="submit" name="transaction_id" class="btn btn-danger">Delete</button></td>
        </tr>
          </form>
    <?php
        }
        ?>
    <?php
    $transaction_id = $_POST['transaction_id'];


      $resultDelete = mysqli_query($connect, "DELETE FROM transactions where $transaction_id = " . $row['id'] . ";");

    ?>
    </tbody>
  </table>
If anymore information or code is needed let me know.
0 x
Patrick Biedermann

User avatar
Patty
New User
Posts: 3
Joined: 31 Aug 2018, 14:40

Re: Code to delete an individual row using a button + confirmation

Post by Patty » 05 Apr 2019, 09:30

Nevermind, I solved it.
1 x
Patrick Biedermann


Post Reply