Forum Moderators: coopster
The error message looks like this
Warning: Cannot modify header information - headers already sent by (output started at /home/kabeet/public_html/flash/page_add.php:4) in /home/kabeet/public_html/flash/page_add.php on line 72
while my codes are the following:
71: if ($resultpage){
72: header("location:detail.php?name_id=$name_id#P$page_id");
73: exit();
74: }else{
What is wrong?
<?php
session_name('YourVisitID');
session_start();
?>
<html>
<head><title>ADD A PAGE</title><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="css/global.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style3 {font-weight: bold}
-->
</style>
</head>
<body bgcolor=#990000><center>
<table width="85%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td bgcolor="#FFFFCC"><div align="center"><font size="2" face="Arial, Helvetica, sans-serif">
</font>
<table width="95%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#FFFFFF"><table width="90%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF" class="main">
<tr>
<td align="center" valign="middle"><div align="center">
<table width="100%" border="0" cellpadding="0" cellspacing="0" bgcolor="#FFFFFF">
<tr>
<td><a href="../index.php"><img src="../images/top_OLD_r1_c1.gif" alt="mydomain.com Homepage" width="62" height="20" border="0"></a></td>
</tr>
</table>
</div></td>
<td align="center" valign="middle"><a href="http://www.mydomain.com/forums/" target="_blank" class="fields"> </a><a href="http://www.mydomain.com/flash/detail.php?name_id=10205" target="_self" class="fields">NCR MAP</a> <a href="http://www.mydomain.com/forums/" target="_blank" class="fields">FORUMS</a> <a href="http://www.mydomain.com/lists/" target="_self" class="fields">NEWSLETTER</a> <a href="http://www.mydomain.com/news.php" target="_self" class="fields">NEWS</a> <a href="http://www.mydomain.com/contact.php" target="_self" class="fields">CONTACT US</a> <a href="http://www.mydomain.com/flash/result01.php?pid=10183&curPage=1&keyword=hotel&file=millennium.swf&category=Hotel&location=" target="_self" class="fields">HOTELS</a> <a href="http://www.mydomain.com/registration.php?int=A3250" target="_self" class="fields">ADVERTISE</a>
<div align="center"> </div></td>
<td><div align="center" class="style3"></div>
<div align="center"><a href="user_main.php" class="fields">MY PAGE</a></div></td>
<td><div align="center"></div>
<div align="center"><a href="user_logout.php" class="fields">LOGOUT</a></div></td>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td bgcolor="#251200"><img src="../images/blank.gif" width="20" height="3"></td>
</tr>
</table></td>
</tr>
</table>
<font size="2" face="Arial, Helvetica, sans-serif">
<?php
$nxt = $_GET["nxt"];//get next page variable from form
$name_id = $_GET["name_id"]; //get iser id variable from link
$page_id = $_GET["page_id"]; //get iser id variable from link
$name_comp = $_GET["name_comp"]; //get iser id variable from link
if (isset($_POST['submit'])){
$message=NULL;
if(empty($_POST['title'])){
$title=FALSE;
$message.="Please enter the title of this page. ";
}else{
$title=$_POST['title'];
}
if(empty($_POST['content'])){
$content=FALSE;
$message.="Please enter contents of this page.";
}else{
$content=$_POST['content'];
}
if ($title && $content){
include("cn.php");
$querypage="insert into tbl_page (name_id, title, content, dt_created)
values('$name_id','$title','$content',NOW())";
$resultpage=mysql_query($querypage);
if ($resultpage){
header("location:detail.php?name_id=$name_id#P$page_id");
$id=$_SESSION['name_id'];
exit();
}else{
$message='<p>Your page could not be saved because of System Error </p><p>'.mysql_error().'</p>';
}
mysql_close();
}else{
$message .='<strong> Please fill in all the information...</strong>';
}
}
if (isset($message)){
echo'<font color="#3300ff">',$message,'</font>';
}
?>
</font> <font color="#666666" size="2" face="Arial, Helvetica, sans-serif"><strong><BR>
<font color="#0033FF">All Entries are required</font></strong></font>
<form method="post" action="<?php $_SERVER['PHP_SELF'];?>">
<TABLE WIDTH="95%" HEIGHT="50%" BORDER="0" align="center" bgcolor="#FFFFCC">
<TR>
<TD VALIGN=TOP ALIGN="RIGHT"> </TD>
<td bordercolor="#FFFFFF" class="eleventextbold"><div align="center">PAGE CONTENT EDITOR </div></td>
<td bordercolor="#FFFFFF" class="redlabelheader"> </td>
</TR>
<TR>
<TD VALIGN=TOP ALIGN="RIGHT"><font size="2" face="Arial, Helvetica, sans-serif"> </font></TD>
<TD colspan="2"><font size="2" face="Arial, Helvetica, sans-serif"> <strong>TITLE</strong><font color="#FF0000"> (maximum of 30 characters only) </font><br>
<INPUT NAME="title" TYPE="TEXT" id="title" value="<?php if(isset($_POST['title'])) echo $_POST['title'];?>" SIZE="50" MAXLENGTH="30">
<BR>
</font>
</TR>
<TR>
<TD VALIGN=TOP ALIGN="RIGHT"> </TD>
<TD colspan="2"><font size="2" face="Arial, Helvetica, sans-serif"> <strong>CONTENTS</strong> <font color="#FF0000"> (html tags are accepted, ex.: <B> <strong>for bold</strong></B>, <I> <em>for Italics</em></>,</font><font size="2" face="Arial, Helvetica, sans-serif"><font color="#FF0000"><BR> for new line</font></font><font color="#FF0000">) </font><br>
<textarea name="content" cols="100" rows="15" wrap="VIRTUAL" id="content"><?php if(isset($_POST['content'])) echo $_POST['content'];?>
</textarea>
<BR><a href="user_main.php" class="fields">BACK TO MY PAGE</a>
</font>
</TR>
</TABLE>
<font size="2" face="Arial, Helvetica, sans-serif"> </font>
<center>
<p><font size="2" face="Arial, Helvetica, sans-serif">
<input type="submit" name="submit" value="i-KABEET">
<input type="reset" value="i-RESET">
</font></p>
</center>
</form>
<font color="#000000" size="3" face="Arial, Helvetica, sans-serif"></font></div></td>
</tr>
</table>
</body>
</html>
function redirect($url) {
if (!headers_sent())
header('Location: '.$url);
else {
echo '<script type="text/javascript">';
echo 'window.location.href="'.$url.'";';
echo '</script>';
echo '<noscript>';
echo '<meta http-equiv="refresh" content="0;url='.$url.'" />';
echo '</noscript>';
}
}
However you may well want to put all of your php code before all of your html (or after I guess, although I've never tried that). As it makes it easier to see what code is attached to that page. If you have blocks of php scattered throughout the page then it is more difficult for you to track down all of your code.
Sometimes it is unavoidable to have your php split up i.e. if you are breaking out of php to echo large amounts of information, but if you are not then put all of it in 1 place so it is easy to find.
If you have a lot of code then you could always include the php from an external file. So if you page is called page.html you have an included file called page.include.php or something like that, so you know what code goes with what page.
Delete the white space before the opening and ending php tags and the problem will definitely be solved.
If you make an analysis, you'll see that the <?php that begins your php code is preceded by an empty or white space. if It's not the case, this is true for the ending tag.
Delete that (or those spaces) and tell me if it doesn't work