search

Home  >  Q&A  >  body text

Delete all data using PHP (delete all data/values ​​in SQL)

<p>Can anyone help me, I am new to PHP programming and I want to know how to make a delete button that will delete all the data/values ​​in a database table This is the table This is my button code This is my delete code Wanted to get help from others This is my button code</p> <pre class="brush:php;toolbar:false;"><form action="delete.php" method="post"> <input type="submit" name="delete" class="btn btn-danger" value="Clear All Data's" style="float: right;"> </form> And this is my delete.php code <?php $server = "localhost"; $username = "root"; $password = ""; $dbname = "qrcodedb"; $conn = new mysqli($server,$username,$password,$dbname); if(isset($_POST['delete'])) { $name = $_POST['delete']; $query = "DELETE FROM table_attendance(NAME,TIMEIN) WHERE name='$name' " $query_run = mysqli_query($conn, $query); if($query_run) { echo '<script> alert("Data Deleted"); </script>'; header("location:index.php"); } else { echo '<script> alert("Data Not Deleted"); </script>'; header("location:index.php"); } } ?></pre></p>
P粉803444331P粉803444331438 days ago443

reply all(1)I'll reply

  • P粉237125700

    P粉2371257002023-09-03 00:40:57

    If you want to remove all data from the table, you can use the truncate command.

    The TRUNCATE TABLE command deletes the data in the table, but does not delete the table itself.

    "TRUNCATE TABLE `table_attendance`"

    reply
    0
  • Cancelreply