•
•
•
•
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 391,944 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,882 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1172 | Replies: 1
![]() |
I have this header information error while I was playing with a script.
Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/layouts/connection.php:8) in /home/user/public_html/layouts/addcomments.php on line 23
I wanted the page to redirect itself after submitting the comment, but I messed up.
I also want to know how do I make the url text area capible of accepting urls and emails.
addcomments.php
[PHP]<?php
include('connection.php');
$action = strip_tags($_GET["action"]);
$id = strip_tags($_GET["id"]);
if ($action=="add")
{
$name = strip_tags($_POST["name"]);
$entry = strip_tags($_POST["entry"]);
$email = strip_tags($_POST["email"]);
// add comments
if (empty($name) || empty($entry))
{
die ("Error, you cannot submit a blank entry.");
}
$q = "insert into layout_comments (id, name, email, date, layout_id, entry) VALUES
('','$name','$email',now(),'$id','$entry')";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());
if ($result)
{
header('Location: addcomments.php');
}
}
else {
?><form action="<?php echo "addcomments.php?action=add&id='$id' "; ?>" method="post">
<table width="130" border="0" cellspacing="1" cellpadding="0">
<tr>
<td height="23" colspan="2"><b>Add Comments</b></td>
</tr>
<tr>
<td>Name
</td>
<td>
<input type="text" name="name" size="30">
</td>
</tr>
<tr>
<td height="25">Url:</td>
<td height="25">
<input type="text" name="email" size="30">
</td>
</tr>
<tr>
<td height="25">Comments
</td>
<td height="25">
<textarea name="entry" cols="30" rows="5"></textarea>
</td>
</tr>
<tr><td colspan=2><input type="submit" value="submit"></td></tr>
</table></form>
<?php
}
?>
<?
$id = strip_tags($_GET["id"]);
$q = "SELECT * from layout_comments where layout_id='$id' order by date desc ";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());
while ($row=mysql_fetch_array($result))
{
$id=$row["id"];
$name=$row["name"];
$email=$row["email"];
$entry=$row["entry"];
$date=$row["date"];
$layout_id = $row["layout_id"];
?>
<table width="80%" border="0" cellspacing="1" cellpadding="0" align="center">
<tr>
<td>Comments for <?php echo "$title"; ?></td>
</tr>
<tr>
<td>
<?php echo "$entry"; ?>
<p>Posted by <a href="<?php echo "$email"; ?>"><?php echo "$name"; ?></a> on <?php
echo "$date"; ?>.</p>
</td>
</tr>
</table>
<?php
}
?>[/PHP]
Warning: Cannot modify header information - headers already sent by (output started at /home/user/public_html/layouts/connection.php:8) in /home/user/public_html/layouts/addcomments.php on line 23
I wanted the page to redirect itself after submitting the comment, but I messed up.
I also want to know how do I make the url text area capible of accepting urls and emails.
addcomments.php
[PHP]<?php
include('connection.php');
$action = strip_tags($_GET["action"]);
$id = strip_tags($_GET["id"]);
if ($action=="add")
{
$name = strip_tags($_POST["name"]);
$entry = strip_tags($_POST["entry"]);
$email = strip_tags($_POST["email"]);
// add comments
if (empty($name) || empty($entry))
{
die ("Error, you cannot submit a blank entry.");
}
$q = "insert into layout_comments (id, name, email, date, layout_id, entry) VALUES
('','$name','$email',now(),'$id','$entry')";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());
if ($result)
{
header('Location: addcomments.php');
}
}
else {
?><form action="<?php echo "addcomments.php?action=add&id='$id' "; ?>" method="post">
<table width="130" border="0" cellspacing="1" cellpadding="0">
<tr>
<td height="23" colspan="2"><b>Add Comments</b></td>
</tr>
<tr>
<td>Name
</td> <td>
<input type="text" name="name" size="30">
</td>
</tr>
<tr>
<td height="25">Url:</td>
<td height="25">
<input type="text" name="email" size="30">
</td>
</tr>
<tr>
<td height="25">Comments
</td> <td height="25">
<textarea name="entry" cols="30" rows="5"></textarea>
</td>
</tr>
<tr><td colspan=2><input type="submit" value="submit"></td></tr>
</table></form>
<?php
}
?>
<?
$id = strip_tags($_GET["id"]);
$q = "SELECT * from layout_comments where layout_id='$id' order by date desc ";
$result= mysql_query($q) or die
("Could not execute query : $q." . mysql_error());
while ($row=mysql_fetch_array($result))
{
$id=$row["id"];
$name=$row["name"];
$email=$row["email"];
$entry=$row["entry"];
$date=$row["date"];
$layout_id = $row["layout_id"];
?>
<table width="80%" border="0" cellspacing="1" cellpadding="0" align="center">
<tr>
<td>Comments for <?php echo "$title"; ?></td>
</tr>
<tr>
<td>
<?php echo "$entry"; ?>
<p>Posted by <a href="<?php echo "$email"; ?>"><?php echo "$name"; ?></a> on <?php
echo "$date"; ?>.</p>
</td>
</tr>
</table>
<?php
}
?>[/PHP]
•
•
Join Date: Jun 2005
Location: Kansas City, Missouri, USA
Posts: 344
Reputation:
Rep Power: 4
Solved Threads: 4
In a quick glance at your code, it does not appear that your are outputting anything before you attempt the header() function. So, my guess is either:
1. connection.php is outputting something using echo(), print(), etc.
2. You have whitespace before or after the initial and final <?PHP ?> tags in the connection.php include file.
I do not understand what you are asking here: It will accept a URL or email address---anything your user can type on the keyboard can be typed into that text input.
1. connection.php is outputting something using echo(), print(), etc.
2. You have whitespace before or after the initial and final <?PHP ?> tags in the connection.php include file.
I do not understand what you are asking here:
•
•
•
•
...how do I make the url text area capible of accepting urls and emails.
![]() |
•
•
•
•
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
•
•
•
•
•
•
•
•
DaniWeb PHP Marketplace
- Cannot modify header information.Headers already sent (PHP)
- How to solve header - error -PHP (PHP)
- Warning: Cannot modify header information (PHP)
- error message with sessions (PHP)
- Php newsletter error (PHP)
Other Threads in the PHP Forum
- Previous Thread: Operating scanners
- Next Thread: i am looking for a script look here for deatils


Linear Mode