CREATE TABLE IF NOT EXISTS `members` ( `id` int(11) NOT NULL AUTO_INCREMENT, `fname` varchar(100) NOT NULL, `lname` varchar(100) NOT NULL, `age` int(5) NOT NULL, ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=1 ;
<?php /* Database config */ $db_host = 'localhost'; $db_user = 'root'; $db_pass = ''; $db_database = 'pdo_ret'; /* End config */ $db = new PDO('mysql:host='.$db_host.';dbname='.$db_database, $db_user, $db_pass); $db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); ?>
<form action="delete.php" method="post"> <table border="1" cellspacing="0" cellpadding="2" > <thead> <tr> <th> </th> <th> First Name </th> <th> Last Name </th> <th> Age </th> </tr> </thead> <tbody> <?php include('connect.php'); $result = $db->prepare("SELECT * FROM members ORDER BY id DESC"); $result->execute(); for($i=0; $row = $result->fetch(); $i++){ ?> <tr class="record"> <td><input name="selector[]" type="checkbox" value="<?php echo $row['id']; ?>"></td> <td><?php echo $row['fname']; ?></td> <td><?php echo $row['lname']; ?></td> <td><?php echo $row['age']; ?></td> </tr> <?php } ?> </tbody> </table> <input type="submit" value="delete" /> </form>
<?php include('connect.php'); $edittable=$_POST['selector']; for($i=0; $i < $N; $i++) { $result = $db->prepare("DELETE FROM members WHERE id= :memid"); $result->bindParam(':memid', $edittable[$i]); $result->execute(); } ?>