下面是混合的HTML和PHP。我沒有將它們分開,因爲標籤被php填充。下拉式數據不會從數據庫中刪除
<form method="post">
<select name="Select User" value="Select User">
<?php
$sth = $conn->prepare('Select username From users');
$sth->execute();
$data = $sth->fetchAll();
foreach ($data as $row){
if($row['username']!="")
echo " <option id=\"Select_user\" name=\"Select_user\" value=\"Select_user\">".$row['username']."</option>";
}
?>
</select><br>
<input type="submit" name="submit" value="Delete"</input>
<?php
if(! empty($_POST['Select_user']))
{
$del_user=$_POST['Select_user'];
$sql = "DELETE FROM users WHERE username=:del";
$sth = $conn->prepare($sql);
$sth->execute(array(':del'=>$del_user));
}
?>
下拉正確地獲取數據,但刪除沒有發生。爲什麼?
回聲你的查詢並查看。 –
我在那看到什麼? –