Cannot modify header information - headers already sent
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>
