使用从数据库字段填充的下拉列表,我需要选择一个选项,然后从数据库中删除它。我试图通过将表单发送到进程php页面来执行此操作,其中我从post数组中提取select选项,然后将其从数据库中删除并返回到索引页面。 从post数组获取数组变量有问题。谁可以帮助一些代码如何获取变量,然后删除mysql标题
<form method="post" action="deleteReview_process.php">
<select name="title">
<?php
while($row = mysql_fetch_array($sql_result)) {
$movieTitle = $row['title'];
?>
<option><?php echo $movieTitle; ?></option>
<?php } ?>
</select>
<input type="submit" name="delete" id="delete" value="delete" />
----和流程页面---
include 'inc/db.inc.php';
if($_POST['delete']) {
$title = $_POST['title'][$movieTitle]; <------ NOT WORKING
$sql = "DELETE" . $title . "FROM pageTitle";
mysql_query($sql, $conn)
or die("couldn't execute query");
header("Location: http://localhost/cms/index.php");
}
else
{
header("Location: http://localhost/cms/deleteReview.php");
}
答案 0 :(得分:2)
由于您的SELECT
元素被命名为“title”,因此当它到达后端脚本时,它将表示为$_POST["title"]
:
$title = $_POST['title'];
此外,您的查询需要更正:
$sql = "DELETE" . $title . "FROM pageTitle";
应该是:
$sql = "DELETE FROM tableName WHERE title = '{$title}'";
答案 1 :(得分:0)
$title
将出现在$_POST['title']
即。 $title = $_POST['title']