我的代碼在php中遇到問題。 我想用一個用戶按下刪除按鈕的時候,從一個表格中刪除多行選擇框。在數據庫中刪除沒有ID的選擇框的行
但我沒有在我的數據庫中的id字段。所以我很難做到這一點 你能幫我嗎?
$user_query= "SELECT * FROM user";
$user_result = mysql_query($user_query);
$count=mysql_num_rows($user_result);
echo "<form name='form1' method='post' action=''>";
echo "<table>";
echo "<tr>";
echo "<th scope='col'>#</th>";
echo "<th scope='col'>username</th>";
echo "<th scope='col'>Email</th>";
echo "<th scope='col'>tel</th>";
echo "<th scope='col'>name</th>";
echo "<th scope='col'>surname</th>";
echo "<th scope='col'>type</th>";
echo "</tr>";
while($row = mysql_fetch_array($user_result))
{
echo "<tr>";
echo '<td><input name="checkbox[]" type="checkbox" username="checkbox[]" value="'.$row['username'].'"></td>';
echo '<td><b>'.$row['username'].'</b></td>';
echo '<td><a href="mailto:'.$row['e_mail'].'" title="send Email">'.$row['e_mail'].'</a></td>';
echo '<td>'.$row['phone_number'].'</td>';
echo '<td>'.$row['name'].'</td>';
echo '<td>'.$row['surname'].'</td>';
echo '<td><img src="images/admin.png" width="40" height="45" title="admin"/></td>';
echo '</tr>';
}
echo '<tr><td colspan="7"><input name="delete" type="submit" id="delete" value="Deleting"></td></tr>';
echo "</table>";
echo "</form>";
if (isset($_POST['delete']))
{
// how can I take checkboxes value and delete values ??
// $sql = "DELETE FROM user WHERE username=...;
$result = mysql_query($sql);
// if successful redirect
if($result)
{
header("location: ShowUsers.php");
}
}
如果你沒有一個ID字段,什麼是你的主鍵?如果我是你,我會做一個ID字段。 –
當我們唯一知道的就是它*沒有特定的列時,不可能告訴你如何從表中刪除特定的行。 – Quentin
我想'用戶名'將是一個獨特的領域,是不是你的ID? – Quentin