Jump to content

Leaderboard

Popular Content

Showing content with the highest reputation on 05/18/2023 in all areas

  1. This is my version. All code is in same file (ie the form calls itself to process the updates) <?php require 'db_inc.php'; // USE YOUR OWN $conn = myConnect('db2'); // CONNECTION CODE ################################################################################ ## UNCOMMENT THIS SECTION TO RECREATE TEST DATA # ################################################################################ /* $conn->query("drop table if exists test"); $conn->query("create table test ( id int not null primary key, descrip varchar(20) ) "); for ($i=1; $i<=10; $i++) { $conn->query("insert into test (id, descrip) values ($i, 'Record $i') "); } */ ################################################################################ ## HANDLE POSTED DATA TO DELETE SELECTED RECORDS # ################################################################################ if ($_SERVER['REQUEST_METHOD'] == 'POST') { if (isset($_POST['del_id'])) { $res = $conn->prepare("DELETE FROM test WHERE id = ? "); $res->bind_param('i', $id); foreach ($_POST['del_id'] as $id) { $res->execute(); } } header("Location: ?"); exit; } ################################################################################ ## GET REMAINING RECORDS AND DISPLAY # ################################################################################ $tdata = ''; $res = $conn->query("SELECT id , descrip FROM test ORDER BY id "); foreach ($res as $r) { $tdata .= "<tr><td>{$r['id']}</td> <td>{$r['descrip']}</td> <td><input type='checkbox' name='del_id[]' value='{$r['id']}'></td> </tr> "; } ?> <!DOCTYPE=html> <html lang="en"> <head> <meta charset='utf-8'> <title>Example</title> <style type='text/css'> th, td { padding: 4px 20px; } th { background-color: black; color: white; } </style> </head> <body> <form method='post'> <table border='1'> <tr><th>ID</th><th>Description</th><th>Select</th></tr> <?=$tdata?> </table> <br> <input type='submit' value='Delete Selected'><br> </form> </body> </html>
    1 point
This leaderboard is set to New York/GMT-04:00
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.