使用PHP删除所有数据(删除SQL中的所有数据/值)
P粉803444331
2023-09-02 13:35:06
<p>有人可以帮助我吗,我是 PHP 编程新手,我想知道如何制作一个删除按钮,该按钮将删除数据库表中的所有数据/值这是该表
这是我的按钮代码
This is my delete code Wanted to get help from others 这是我的按钮代码</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>
如果您想从表中删除所有数据,则可以使用截断命令。
TRUNCATE TABLE 命令删除表内的数据,但不会删除表本身。