Delete all data using PHP (delete all data/values in SQL)
P粉803444331
2023-09-02 13:35:06
<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>
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.