Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form method="post" action = "del.php">
- <table border = "1">
- <tr>
- <th>Employee Name</th>
- </tr>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "lavoratori";
- // Create connection
- $conn = new mysqli($servername, $username, $password, $dbname);
- // Check connection
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- $sql = "SELECT nome, id FROM operai";
- $result = $conn->query($sql);
- if ($result->num_rows > 0) {
- // output data of each row
- while($row = $result->fetch_assoc()) {
- echo"<tr>";
- echo'<td><input type = "checkbox" name = checkbox[]" value = '.$row['id']."<td>".$row['nome']."</td>";
- echo"</tr>";
- }
- echo"</table>";
- }
- $conn->close();
- ?>
- <input type = "submit" name = "delete" id = "delete" value = "Delete Records">
- </form>
- <?php
- $servername = "localhost";
- $username = "root";
- $password = "";
- $dbname = "lavoratori";
- $conn = new mysqli($servername, $username, $password, $dbname);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- if(isset($_POST['delete'])){
- $chkarr = $_POST['checkbox'];
- foreach($chkarr as $id){
- $sql = "DELETE FROM operai WHERE id = .$id.";
- $result = $conn->query($sql);
- }
- header("Location: /test_purpose/home.php");
- }
- $conn->close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement