mysql 使用PHP删除所有数据(删除SQL中的所有数据/值)

oknwwptz  于 2022-12-17  发布在  Mysql
关注(0)|答案(1)|浏览(132)

有人能请帮助我吗,我是新来的PHP编程我想知道如何做一个删除按钮,将删除数据库This is the tableThis is my button codeThis is my delete code上的表中的所有数据/值想要得到别人的帮助这是我的按钮代码

<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");
  }
}
?>
rnmwe5a2

rnmwe5a21#

如果要从表中删除所有数据,则可以使用truncate命令。
TRUNCATE TABLE命令删除表中的数据,但不删除表本身。

"TRUNCATE TABLE `table_attendance`"

相关问题