【发布时间】:2013-07-30 13:09:39
【问题描述】:
我已经在我的网站的管理方面工作了一段时间。
我已经成功地创建了一个添加页面,以便在 mysql 中将项目添加到我的 mobi DB。
但是当添加一个delete.php 页面时,它并不能很好地工作。
页面加载并在下拉菜单中列出数据库中的所有文章,但是当我选择不再需要的文章时,它会返回到页面上编码的索引,但检查我的网站它不会删除文章。
我的 DELETE.PHP 页面是这样的:
<?php
session_start();
include_once('../include/connection.php');
include_once('../include/article.php');
$article = new storearticle;
if (isset($_SESSION['logged_in'])) {
if (isset($_GET['title'])) {
$id = $_GET['title'];
$query = $pdo->prepare('DELETE FROM mobi WHERE promo_title = ?');
$query->bindValue(1, $title);
$query->execute();
header('Location: index.php');
}
$articles = $article->fetch_all();
?>
<html>
<head>
<title>Delete Article</title>
<link rel="stylesheet" href="../other.css" />
</head>
<body>
<div class="container">
<a href="index.php" id="logo"><b>← Back</b></a>
<br />
<div align="center">
<h4>Select an article to delete:</h4>
<form action="delete.php" method="get">
<select onchange="this.form.submit();" name="title">
<?php foreach ($articles as $article){ ?>
<option value="<?php echo $article['promo_title']; ?>"><?php echo $article['promo_title']; ?></option>
<?php } ?>
</select>
</form>
</div>
</div>
</body>
</html>
<?php
} else {
header('Location: index.php');
}
?>
有人能看出我哪里出错了吗?
如果您需要更多信息,请告诉我。
【问题讨论】:
-
你能打印_r($articles); ..
-
嗨,用户...我让你将 $id 更改为 $title,如下所述。谢谢。
标签: php mysql content-management-system