我的数据库中有一些表,我想在点击按钮上删除它 选择选项标签
<?php
$db = mysqli_connect('localhost','root','','post15');
if (isset($_POST['submit2'])) {
$query = $db->query("DELETE FROM posted WHERE title");
if ($query) {
echo "Post DELETED";
}
}?>
<form method="post" action="admin.php">
<select name="categoryBox">
<?php
$query = $db->query("SELECT * FROM posted");
while ($row = $query->fetch_object()){
echo "<option value='".$row->id."'>".$row->title."
</option>";
}
?>
</select>
<input type="submit" name="submit2">
</form>
答案 0 :(得分:0)
您提供的代码不起作用,您尝试使用标题删除,但您的下拉选项值不是标题,因此您应该查看删除所选标题的ID
if (isset($_POST['submit2'])) {
$query = $db->prepare("DELETE FROM posted WHERE id = ? ");
$query->bind_param("i",$_POST['categoryBox']);
if ($query->execute()) {
echo "Post DELETED";
}
答案 1 :(得分:0)
试试这个。
<form method="post">
Id: < input type="text" name="id">
<input type="submit" value="submit">
</form>
<?php
$_POST['id']
$db=mysql_connect("localhost","root","");
mysql_select_db("post15",$db);
mysql_query("DELETE FROM posted WHERE id=$id",$db);
echo"ID ".$_POST['id']." has been Deleted ";
?>