Jump to content

[SOLVED] Cannot modify header information


S A N T A

Recommended Posts

Ok so i am working on a blog and so far everything is working but now i am trying to make an archive of all the categories but when i try to use it

it displays the categories

Life

Work

Music

Food

 

from a database but when i click them its suppose to display all the entries in that category but it displays this error:

 

Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\header.php:11) in C:\xampp\htdocs\viewcat.php on line 15

 

here is the code

 

<?php

require("config.php");

require("header.php");
?>
<div id="main">
<?php

if(isset($_GET['id']) == TRUE) {
if(is_numeric($id) == FALSE) {
	$error = 1;
}
if($error == 1) {
header("Location: " . $config_basedir . "/viewcat.php");
}
else {
	$validcat = $_GET['id'];
}
}
else {
$validcat = 0;
}

$db = mysql_connect($dbhost, $dbuser);
mysql_select_db($dbdatabase, $db);
$sql = "SELECT * FROM categories";
$result = mysql_query($sql);




while($row = mysql_fetch_assoc($result)) {
if($validcat == $row['id']) {
	echo "<strong>" . $row['cat'] . "</strong><br />";

	$entriessql = "SELECT * FROM entries WHERE cat_id = " . $validcat . " ORDER BY dateposted DESC;";

	$entriesres = mysql_query($entriessql)or die(mysql_error(). "   in $sql");
	$numrows_entries = mysql_num_rows($entriesres);

	echo "<ul>";
	if($numrows_entries == 0) {
		echo "<li>No entries!</li>";
	}
	else {
		while($entriesrow = mysql_fetch_assoc($entriesres)) {
			echo "<li>" . date("D jS F Y g.iA", strtotime($entriesrow['dateposted'])) . " - <a href='viewentry.php?id=" . $entriesrow['id'] . "'>" . $entriesrow['subject'] . "</a></li>";
		}
	}
	echo "</ul>";
}
else {
	echo "<a href='viewcat.php?id=" . $row['id'] . "'>" . $row['cat'] . "</a><br />";
	}
}

require("footer.php");
?>
</div>

Link to comment
https://forums.phpfreaks.com/topic/103187-solved-cannot-modify-header-information/
Share on other sites

header.php =

 

<?php
require("config.php");
$db = mysql_connect($dbhost, $dbuser);
mysql_select_db($dbdatabase, $db);
?>

<DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title><?php echo $config_blogname; ?></title>
<link rel="stylesheet" href="stylesheet.css" type="text/css" />
</head>
<body>
<div id="header">
<h1><?php echo $config_blogname; ?></h1>


</div>
<div id="menu">
<center><a href="index.php">home</a></center>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.