Skip to main content
Known Participant
August 2, 2009
Question

Cannot modify header information - headers already sent

  • August 2, 2009
  • 2 replies
  • 2961 views

Hi everyone!

I have searched this forum for solving my problem, but I did not get any solution that is why I started

a new thread. My problem is that I have created a form and when I click on the insert button

this warning is displayed

Warning:  Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\testingpage\index.php:7) in C:\xampp\htdocs\testingpage\knjiga\nov.php on line 47 (this line is in red in the code).The page is a switch page and I have removed everything so the whole code is pasted here.

I thank you in advance for any help that I will recieve from you to solve my problem.

Best regards from Sweden.

<?php require_once('../Connections/test.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;
  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);
switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;   
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
}
  return $theValue;
}
}
$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "dodaj")) {
  $insertSQL = sprintf("INSERT INTO knjiga_gostov (ime, email, kraj, datum, sporocilo) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($_POST['ime'], "text"),
                       GetSQLValueString($_POST['email'], "text"),
                       GetSQLValueString($_POST['kraj'], "text"),
                       GetSQLValueString($_POST['datum'], "text"),
                       GetSQLValueString($_POST['sporocilo'], "text"));
  mysql_select_db($database_test, $test);
  $Result1 = mysql_query($insertSQL, $test) or die(mysql_error());
  $insertGoTo = "dodano.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
}
  header(sprintf("Location: %s", $insertGoTo));
}
?><div id="pageheader">Vpis v knjigo gostov</div>
<div id="content">
  <form name="dodaj" method="POST" action="<?php echo $editFormAction; ?>">
  <table width="250" border="0">
  <tr>
    <td>Ime:</td>
    <td><label>
      <input type="text" name="ime" id="ime">
    </label></td>
  </tr>
  <tr>
    <td>Email:</td>
    <td><label>
      <input type="text" name="email" id="email">
    </label></td>
  </tr>
  <tr>
    <td>Kraj:</td>
    <td><label>
      <input type="text" name="kraj" id="kraj">
    </label></td>
  </tr>
  <tr>
    <td>Sporočilo:</td>
    <td> </td>
  </tr>
  <tr>
    <td colspan="2"><label>
    <textarea name="sporocilo" id="sporocilo" cols="45" rows="5"></textarea>
    </label></td>
    </tr>
  <tr>
    <td colspan="2"><input name="datum" type="hidden" id="datum" value="<?php echo (date('d.m.Y')); ?>"></td>
    </tr>
  <tr>
    <td colspan="2"><label>
      <input type="submit" name="potrditev" id="potrditev" value="Vpiši v knjigo">
    </label></td>
    </tr>

</table>

  <input type="hidden" name="MM_insert" value="dodaj">
  </form>
</div>

This topic has been closed for replies.

2 replies

David_Powers
Inspiring
August 3, 2009

MooskirchnerQuintett wrote:

Warning:  Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\testingpage\index.php:7) in C:\xampp\htdocs\testingpage\knjiga\nov.php on line 47 (this line is in red in the code).

The error message tells you that the output started at line 7 of index.php. That's where you need to look for the problem, not in nov.php.

Participating Frequently
August 2, 2009

It means that the page (or the included page) has already sent the headers so it cannot redirect to a new page. I don't see any html tags on that prior to the redirect. Did you include them in the test.php page?

Known Participant
August 2, 2009

The only html tags <head> and <body> are on my index.php page where the switching happens.

Participating Frequently
August 3, 2009

I can't tell which page is which from your code. It appears you have pasted code from more than one page in your post. What do you mean "where the switching happens" ?  If you are trying to redirect (I guess that's what you mean by switch) then you cannot have any html before that occurs.