簡體   English   中英

按鈕的代碼,用於從MySQL表中刪除特定條目(使用php)?

[英]Code for button to delete specific entries from a MySQL table (using php)?

目前,我的代碼打印出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>

delete.php將其放在td tag然后在delete.php編寫刪除查詢delete.php

嘗試這個

<form action="" method="post">
<?php
if(isset($_REQUEST['delete']) and is_numeric($_REQUEST['delete']))
{
        $sql = "DELETE FROM bookings WHERE id=3";
}
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><a href='delete.php?delete=".$student['id']."'>Delete</a> </td>";
        echo "</tr>";
}
?>
</form>

*

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM