gpt4 book ai didi

php - 从 MySQL 表中删除特定条目的按钮代码(使用 php)?

转载 作者:行者123 更新时间:2023-11-30 22:48:32 24 4
gpt4 key购买 nike

目前,我的代码打印出一个 mysql 表的内容,它包含一个删除按钮。我怎样才能得到这个按钮来从 mysql 表中删除相应的条目?另外,我怎样才能使表格只显示特定数据的条目(例如,不显示今天日期之前的条目)?任何帮助将不胜感激。

<?php

include('php/connect.php');

mysql_connect ($host,$user,$password);
mysql_select_db('booking');

$sql="SELECT *FROM bookings";
$records = mysql_query($sql);

?>

<html>

<head>
<title>Records</title>
</head>

<body>

<table width = "600" border = "1" cellpadding = "1" cellspacing = "1">
<tr>

<th>ID</th>
<th>Date</th>
<th>Start</th>
<th>Name</th>
<th>E-mail</th>
<th>Phone</th>
<th>Delete</th>

</tr>

<form action="" method="post">

<?php

if(isset($_POST['delete']) and is_numeric($_POST['delete']))
{
$sql = "";
}

while ($student = mysql_fetch_assoc ($records)){

echo "<tr>";
echo "<td>".$student['id']."</td>";
echo "<td>".$student['date']."</td>";
echo "<td>".$student['start']."</td>";
echo "<td>".$student['name']."</td>";
echo "<td>".$student['email']."</td>";
echo "<td>".$student['phone']."</td>";
echo "<td> <input type=submit name=delete id=".$student['id']." value=delete </td>";
echo "</tr>";

}

?>

</form>

</table>
</body>
</html>

最佳答案

你可以试试这个..

<a href='delete.php?id=".$student['id']."'>Delete</a>

简单地将其放入td 标签 并在delete.php 中编写删除查询。

关于php - 从 MySQL 表中删除特定条目的按钮代码(使用 php)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28851593/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com