我的代码有什么问题,每当我试图删除一条记录时给出警告信息.....请帮帮我
警告:无法修改标头信息 - 已发送的标头 (输出从C:\ xampp \ htdocs \ CMS \ admin \ Categories.php:10开始) 第181行的C:\ xampp \ htdocs \ CMS \ admin \ Categories.php
<div id="wrapper">
<!-- Navigation -->
<?php include "includes/Navigation.php";?>
<!-- Top Menu Items -->
<ul class="nav navbar-right top-nav">
<li><a href="../index.php"> Home Page </a></li>
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown"><i class="fa fa-user"></i> John Smith <b class="caret"></b></a>
<ul class="dropdown-menu">
<li>
<a href="#"><i class="fa fa-fw fa-user"></i> Profile</a>
</li>
<li class="divider"></li>
<li>
<a href="#"><i class="fa fa-fw fa-power-off"></i> Log Out</a>
</li>
</ul>
</li>
</ul>
<!-- Sidebar Menu Items - These collapse to the responsive navigation menu on small screens -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav side-nav">
<li>
<a href="index.html"><i class="fa fa-fw fa-dashboard"></i> Dashboard</a>
</li>
<li>
<a href="javascript:;" data-toggle="collapse" data-target="#posts_dropdown"><i class="fa fa-fw fa-arrows-v"></i> posts <i class="fa fa-fw fa-caret-down"></i></a>
<ul id="posts_dropdown" class="collapse">
<li>
<a href="#">view all pasts</a>
</li>
<li>
<a href="#">add posts</a>
</li>
</ul>
</li>
<li>
<a href="bootstrap-grid.html"><i class="fa fa-fw fa-wrench"></i> Categories</a>
</li>
<li>
<a href="blank-page.html"><i class="fa fa-fw fa-file"></i> Comments </a>
</li>
<li>
<a href="javascript:;" data-toggle="collapse" data-target="#demo"><i class="fa fa-fw fa-arrows-v"></i> Users <i class="fa fa-fw fa-caret-down"></i></a>
<ul id="demo" class="collapse">
<li>
<a href="#">Dropdown Item</a>
</li>
<li>
<a href="#">Dropdown Item</a>
</li>
</ul>
</li>
<li>
<a href="index-rtl.html"><i class="fa fa-fw fa-dashboard"></i> Profile</a>
</li>
</ul>
</div>
<!-- /.navbar-collapse -->
</nav>
<div id="page-wrapper">
<div class="container-fluid">
<!-- Page Heading -->
<div class="row">
<div class="col-lg-12">
<h1 class="page-header">
Welcome to Admin
<small> Rajsekhar</small>
</h1>
<div class="col-xs-6">
<?php
if(isset($_POST['submit']))
{
$cat_title = $_POST['cat_title'];
if ($cat_title == "" || empty($cat_title)) {
# code...
echo "this field should not be empty ";
} else {
$query = "INSERT INTO category(cat_title) VALUES ('{$cat_title}')";
$create_cat_query = mysqli_query($connection,$query);
if(!$create_cat_query){
die('query failed' . mysqli_error($connection));
}
}
}
?>
<form action="" method="POST">
<div class="form-group">
<label for="cat-title">Add Category</label>
<input type="text" class="form-control" name="cat_title">
</div>
<div class="form-group">
<input type="submit" name="submit" class="btn btn-primary" value="Add Category">
</div>
</form>
</div>
<!-- Add category form -->
<div class="col-xs-6">
<table class="table table-bordered table-hover">
<thead>
<tr>
<th>Id</th>
<th>category title</th>
</tr>
</thead>
<tbody>
<?php
$query = "SELECT * FROM category;";
$slect_all_category = mysqli_query($connection,$query);
while($row = mysqli_fetch_assoc($slect_all_category)){
$cat_id = $row['cat_id'];
$cat_title = $row['cat_title'];
echo "<tr>";
echo "<td> {$cat_id}</td>";
echo "<td> {$cat_title}</td>";
echo "<td> <a href = 'Categories.php?delete={$cat_id}'> Delete </a>";
echo "</tr>";
}
?>
<tr>
</tr>
</tbody>
</table>
<?php
if(isset($_GET['delete']))
{
$delete_id = $_GET['delete'];
$query = "DELETE FROM Category where cat_id = {$delete_id} ";
$delete_query = mysqli_query($connection,$query);
header("Location: Categories.php");
if(!$delete_query)
{
die('Query Failed' . mysqli_error($connection) );
}
}
?>
</div>
</div>
</div>
<!-- /.row -->
</div>
<!-- /.container-fluid -->
</div>
<!-- /#page-wrapper -->
答案 0 :(得分:0)
在页面开头移动你的帖子逻辑。
一旦脚本的html部分启动,它会自动开始将数据推送到浏览器,响应的标题应该首先出现。然后你包括一些可能想要向浏览器返回错误的php文件,但输出已经开始,所以标题不能被修改,所以php给出了这个错误
<?php
if(isset($_GET['delete']))
{
$delete_id = $_GET['delete'];
$query = "DELETE FROM Category where cat_id = {$delete_id} ";
$delete_query = mysqli_query($connection,$query);
header("Location: Categories.php");
if(!$delete_query)
{
die('Query Failed' . mysqli_error($connection) );
}
}
?>
//rest of the page