# Header error

**URL:** <https://forum.kirupa.com/t/header-error/234725>\
**Category:** Uncategorized\
**Created:** [August 5, 2007, 9:59am UTC](https://forum.kirupa.com/t/header-error/234725 "2007-08-05T09:59:14Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![heinlein](https://avatars.discourse-cdn.com/v4/letter/h/f17d59/32.png) [@heinlein](https://forum.kirupa.com/u/heinlein)\
**Post date:** [August 5, 2007, 9:59am UTC](https://forum.kirupa.com/t/header-error/234725/1 "2007-08-05T09:59:14Z")

</div>

hi, i’m new to php and i’m actually learning from a book so the code i wrote is basically from someone else but it seems that i have error when running it.

here is the error:  
**Warning** : Cannot modify header information - headers already sent by (output started at C:\wamp\www\Forum\do\_addtopic.php:3) in **C:\wamp\www\Forum\do\_addtopic.php** on line **5**

[//addtopic.php](https://addtopic.php) code

```auto

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Add a Topic</title>
</head>
<body>
<h1>Add a Topic</h1>
<form method = "post" action="do_addtopic.php">
<p>
<strong>Your E-Mail Address:</strong><br/>
<input type = "text" name="topic_owner" size="40" maxlength="150"/>
</p>
<p>
<strong>Topic Title:</strong><br/>
<input type = "text" name="topic_title" size="40" maxlength="150"/>
</p>
<p>
<strong>Post Text:</strong><br/>
<textarea name="post_text" rows="8" cols="40" wrap="virtual"></textarea>
</p>
<p>
<input type = "submit" name="submit" value = "Add Topic"/>
</p>
</form>
</body>
</html>

```

//do\_addtopic.php code

```php

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<?php
 if ((!$_POST[topic_owner]) || ($_POST[topic_title]) || ($_POST[post_text])) { 
  header('Location: addtopic.php', true);
  exit;
 }
 
 
 $conn = mysql_connect("localhost", "heinlein", "56537484") or die(mysql_error());
 mysql_select_db("forum", $conn) or die(mysql_error());
 
 $add_topic = "INSERT INTO forum_topics VALUES ('', '$_POST[topic_title]', now(), '$_POST[topic_owner]')";
 mysql_query($add_topic, $conn) or die(mysql_error());
 
 $topic_id = mysql_insert_id();
 
 $add_post = "INSERT INTO forum_posts VALUES ('', '$topic_id', '$_POST[post_text]', now(), '$_POST[topic_owner]')";
 mysql_query($add_post, $conn) or die(mysql_error());
 
 $msg = "<p>The <strong>$topic_title</strong> topic has been created.</p>"
?>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>New Topic Added</title>
</head>
<body>
<h1>New Topic Added</h1>
<?php print $msg; ?>
</body>
</html>

```

hope someone will tell me wat mistakes i hv made for this one. thanks
