我正在創建用於管理數據庫的用戶界面。每個條目都有兩個單選按鈕,一個用於驗證(並隨後通過電子郵件發送給相關機構),另一個用於刪除條目。代碼如下所示,粗體部分是涉及此功能的部分。 有幾個問題: 1)有沒有可能這樣做沒有表單屬性?如果是這樣,我該怎麼做?傳遞php變量
2)使用form屬性,我使用'handle.php'來刪除每個條目。在「handle.php」的語法包括這條線現在
$sql="DELETE FROM rti WHERE ID=x"; //x here is the ID number to delete.
,如何傳遞ID的值,以及從我的接口,這樣的代碼上面的行刪除對應於該按鈕的條目那被壓了?
<html>
<head>
<style>
* {
margin: 0px;
padding: 0px;
}
div.topbar {
position: relative;
background-color: black;
height: 45px;
text-align: center;
font-family: Calibri;
font-size: 30px;
padding-top: 10px;
}
div.topbar img {
position: absolute;
left: 10px;
top: 0px;
}
div.topbar span {
color: white;
}
div.container {
background-color: #a5a5a5;
width: 100%;
height: 100%;
color: white;
}
div.data {
padding: 20px;
}
table {
background-color: #b1b1b1;
border-collapse: collapse;
}
th, td {
text-align: center;
border: solid 1px black;
margin: 0px;
}
th.one {
width: 50px;
}
th.two{
width: 150px;
}
th.three {
width: 75px;
}
th.four {
width: 200px;
}
div.validation {
background-color: #b5b5b5;
width: 200px;
height: 100%;
position: relative;
left: 1100px;
bottom: 300%;
text-align: center;
border-left: solid 1px black;
}
</style>
</head>
<body>
<div class = "topbar"><img src="logo.png"><span>RTI DATABASE</span></div>
<div class = "container">
<div class ="data">
<?php
$servername="localhost";
$username="root";
$password='';
$conn=mysql_connect($servername, $username, $password) or die ("Error connecting to mysql server: ".mysql_error());
$dbname = 'bsp';
mysql_select_db($dbname, $conn) or die ("Error selecting specified database on mysql server: ".mysql_error());
$sql="SELECT * FROM rti";
$result=mysql_query($sql) or die ("Query to get data from firsttable failed: ".mysql_error());
echo "<table>";
echo "<tr>";
echo '<th class="one">ID</th>
<th class="two">Name</th>
<th class="three">Board</th>
<th class="four">Query</th>
<th class="five">Validate</th>
<th class="six">Delete</th>
<th class="seven">Submit</th>';
echo "</tr>";
while ($row=mysql_fetch_array($result)) {
$id=$row["ID"];
$name=$row["name"];
$board=$row["board"];
$query=$row["query"];
echo "<tr>";
echo "<td>$id</td>
<td>$name</td>
<td>$board</td>
<td>$query</td>
**<form action='handle.php' method='POST'>
<td><input type='radio' name='option' value='validate'></td>
<td><input type='radio' name='option' value='delete'></td>
<td><input type='submit' value='Submit' name='submit'>
</form></td>";
echo "</tr>";**
}
echo "</table><br>";
?>
</div>
</div>
</body>
</html>
是否需要在表格上使用表格標籤?您也可以使用標籤嘗試。 –
**停用**使用不推薦使用的'mysql_ *'API。使用'mysqli_ *'或'PDO' – Jens