delete a multiple selected rows in PHP without Ajax – onlinecode
In this post we will give you information about delete a multiple selected rows in PHP without Ajax – onlinecode. Hear we will give you detail about delete a multiple selected rows in PHP without Ajax – onlinecodeAnd how to use it also give you demo for it if it is necessary.
In this post, we have shared How To delete multiple selected rows in PHP without Ajax. normally we have added the button or anchor tag for delete single data. but when we have large data and we will delete the single data, at that time it will take more time. Then at that time, this functionality will helpful.
For discussion, How To delete multiple selected rows in PHP without Ajax. after then configuration database and fetch the data and also we will have set bootstrap and take the form and table. here pass data into TR and TD tag through ‘WHILE’ loop and also take checkbox with multiple names in every single row.
When we will have checked the checkbox and then after click on the delete button then the form will be submitted. it will count the number of checkboxes that are checked. it will get the checkbox value using the for a loop after then delete data one by one.
See below an example of How To delete multiple selected rows in PHP without Ajax.
<?php $hostname="localhost"; $username="root"; $password=""; $database="php"; $conn = mysqli_connect($hostname,$username,$password,$database); if(isset($_POST['btnDelete'])) { $checkbox = $_POST['check']; for($i=0;$i<count($checkbox);$i++) { $del_id = $checkbox[$i]; mysqli_query($conn,"delete from users where id='".$del_id."'"); $message = "Data Successfully Deleted"; } } $result = mysqli_query($conn,"select * from users"); ?> <!DOCTYPE html> <html> <head> <title>How To delete a multiple selected rows in PHP without Ajax</title> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/css/bootstrap.min.css"> <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script> <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.0/js/bootstrap.min.js"></script> </head> <body> <div > <div > <div > <?php if(isset($message)) { ?> <div > <a href="#" data-dismiss="alert" aria-label="close">×</a> <strong>Success!</strong> <?php echo $message; ?> </strong> </div> <?php } ?> </div> </div> <form method="post" action=""> <div > <div > <button type="submit" name="btnDelete">DELETE</button> </div> </div> <br/> <table > <thead> <tr> <th><input type="checkbox" id="checkAll"> <label for="checkAll">Select All</label></th> <th>Id</th> <th>First Name</th> <th>Last Name</th> <th>Email</th> <th>Created Date</th> </tr> </thead> <?php $i=0; while($row = mysqli_fetch_array($result)) { ?> <tr> <td><input type="checkbox" id="checkItem" name="check[]" value="<?php echo $row["id"]; ?>"></td> <td><?php echo $row["id"]; ?></td> <td><?php echo $row["first_name"]; ?></td> <td><?php echo $row["last_name"]; ?></td> <td><?php echo $row["email"]; ?></td> <td><?php echo $row["created"]; ?></td> </tr> <?php $i++; } ?> </table> </form> </div> <script> $("#checkAll").click(function () { $('input:checkbox').not(this).prop('checked', this.checked); }); </script> </body> </html>
I have shared demo Button or URL. So you can click on Button or URL and show the demo.
Hope this code and post will helped you for implement delete a multiple selected rows in PHP without Ajax – onlinecode. if you need any help or any feedback give it in comment section or you have good idea about this post you can give it comment section. Your comment will help us for help you more and improve us. we will give you this type of more interesting post in featured also so, For more interesting post and code Keep reading our blogs