我试图通过从下拉菜单中选择新闻事件来从数据库中删除新闻事件。当用户选择新闻标题并按下提交按钮时,应从相关表中删除新闻项目。无论我尝试什么,我都无法让它正常工作。对不起,我是 PHP 新手。有人可以帮忙吗?这是下拉菜单:
$sql="SELECT newstitle FROM $tbl_name";
$result=mysql_query($sql);
?>
<select name="select1">
<?php
while ($row = mysql_fetch_array($result, MYSQL_ASSOC)){
?>
<option value="<?php echo $row['newstitle'];?>"> <?php echo $row['newstitle'];?> </option>
<?php
}
?>
</select>
<td><center><input type="submit" name="delete" value="delete"></center></td>
按下按钮时,我还有要从数据库中删除的代码吗?
$delete=$_POST['delete'];
$delete = mysql_real_escape_string($delete);
mysql_query ("DELETE FROM $tbl_name WHERE newstitle='$delete'") or die ("Error- news has not been deleted");
echo "News has been deleted";
header("Location: newsdeleted.php");