index.php file
- <!DOCTYPE html>
- <html lang="en">
- <head>
- <meta charset="utf-8">
- <meta http-equiv="X-UA-Compatible" content="IE=edge">
- <meta name="viewport" content="width=device-width, initial-scale=1">
- <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
- <title>Bootstrap 101 Template</title>
- <!-- Latest compiled and minified CSS -->
- <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
- </head>
- <body>
- <div class="container">
- <div class="col-md-6">
- <h1>multi delete</h1>
- <form method="post" action="delete.php">
- <?php
- require_once 'db.php';
- $stmt = $db_con->prepare("select * from multi");
- $stmt->execute();
- while($row=$stmt->fetch(PDO::FETCH_ASSOC)){
- ?>
- <input type="checkbox" name="delete23[]" value="<?php echo $row['id']; ?>">
- <?php echo $row['id']; ?>
- <?php echo $row['multi']; ?><hr>
- <?php
- }
- ?>
- <input type="submit" name="delete" class="btn-warning" value="submit">
- </form>
- </div>
- </div>
- </body>
- </html>
db.php file
- <?php
- $db_host = "localhost";
- $db_name = "hey";
- $db_user = "root";
- $db_pass = "";
- try{
- $db_con = new PDO("mysql:host={$db_host};dbname={$db_name}",$db_user,$db_pass);
- $db_con->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- catch(PDOException $e){
- echo $e->getMessage();
- }
- ?>
delete.php file
- <?php
- require_once 'db.php';
- if($_POST['delete'])
- {
- $delete= implode(",", $_POST['delete23']);
- if($delete=='')
- {
- echo "<script>alert('Nothing Selected to Delete!!!'); window.location='index.php'</script>";
- }
- $sql = "Delete from multi where id IN ($delete)";
- // use exec() because no results are returned
- $db_con->exec($sql);
- echo "<script>alert('Successfully Delete!!!'); window.location='index.php'</script>";
- }
- ?>
No comments:
Post a Comment