Forums
This topic is locked
"Cannot modify header information" problems!!
13 Aug 2006 00:12:09 Adam Fish posted:
Hi!I have a small problem thats driving me crazy and i'm unable to figure out what is casuing the "Cannot modify header information" error I am getting when I submit data to my database.
The exact error is: <b>Warning: Cannot modify header information - headers already sent by (output started at /home/itsnota/public_html/music/register_employee.php:1) in /home/itsnota/public_html/music/register_employee.php on line 53</b>
I have checked my code over and over again but can't find what is causing the problem. Can anyone help me out?
The code:
<?php require_once('Connections/conn_music.php'); ?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = ""
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $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"] == "frmRegisterEmployee") {
$insertSQL = sprintf("INSERT INTO userdata (userID, Name, EMail, Address, Postcode, Username, Password, RegistrationDate, RegistrationIP) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($_POST['userID'], "text",
GetSQLValueString($_POST['Name'], "text",
GetSQLValueString($_POST['EMail'], "text",
GetSQLValueString($_POST['Address'], "text",
GetSQLValueString($_POST['Postcode'], "text",
GetSQLValueString($_POST['Username'], "text",
GetSQLValueString($_POST['Password'], "text",
GetSQLValueString($_POST['RegistrationDate'], "text",
GetSQLValueString($_POST['RegistrationIP'], "text");
mysql_select_db($database_conn_music, $conn_music);
$Result1 = mysql_query($insertSQL, $conn_music) or die(mysql_error());
$insertGoTo = "index.php";
if (isset($_SERVER['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<link rel="stylesheet" type="text/css" href="andreas01.css" media="screen" title="andreas01 (screen)" />
<link rel="stylesheet" type="text/css" href="print.css" media="print" />
<title>Music Connections | Register Employee Account</title>
<link href="css/andreas01.css" rel="stylesheet" type="text/css" />
</head>
<body><div id="wrap">
<div id="header">
<h1>Music Connections </h1>
</div>
<img id="frontphoto" src="images/front.jpg" width="760" height="175" alt="" />
<div id="avmenu">
<h2 class="hide">Menu:</h2>
<ul>
<li><a href="index.php">Welcome!</a></li>
<li><a href="register.php">Register</a></li>
<li><a href="myaccount/index.php">My Account </a></li>
<li><a href="postjob.php">Post New Advert </a></li>
<li><a href="viewjobs.php">View Job Avderts </a>
<li><a href="searchjobs.php">Search Jobs </a></li>
<li><a href="help.php">Help/FAQ</a></li>
<li><a href="contact.php">Contact</a></li>
</ul>
<div class="announce">
<h3>Latest jobs:</h3>
<p><strong>"Latest jobs info to appear here."</strong></p>
<p class="textright"><a href="index.html">Read more...</a></p>
</div>
</div>
<div id="content">
<h2>Register employee account </h2>
<p>To register an employee account please fill the form below and click submit. You will have the opptunity to confirm your details and make any final changes at the next stage. </p>
<form action="<?php echo $editFormAction; ?>" id="frmRegisterEmployee" method="POST" name="frmRegisterEmployee">
<table width="200" border="0" cellpadding="0">
<tr>
<th class="tables" scope="col">Name</th>
<th scope="col"><label>
<div align="left">
<input name="Name" type="text" id="Name" />
</div>
</label></th>
</tr>
<tr>
<th class="tables" scope="col">E-Mail Address </th>
<th scope="col"><div align="left">
<label>
<input name="EMail" type="text" id="EMail" />
</label>
</div></th>
</tr>
<tr>
<th scope="col">Address</th>
<th scope="col"><div align="left">
<label>
<textarea name="Address" rows="5" id="Address"></textarea>
</label>
</div></th>
</tr>
<tr>
<th scope="col">Postcode</th>
<th scope="col"><div align="left">
<label>
<input name="Postcode" type="text" id="Postcode" />
</label>
</div></th>
</tr>
<tr>
<th scope="col"> </th>
<th scope="col"><div align="left"></div></th>
</tr>
<tr>
<th scope="col">Username</th>
<th scope="col"><div align="left">
<label>
<input name="Username" type="text" id="Username" />
</label>
</div></th>
</tr>
<tr>
<th scope="col">Password</th>
<th scope="col"><div align="left">
<label>
<input name="Password" type="text" id="Password" />
</label>
</div></th>
</tr>
<tr>
<th scope="col"> </th>
<th scope="col"><div align="left"></div></th>
</tr>
<tr>
<th scope="col">Account Type </th>
<th scope="col"><div align="left">
<label>
<input name="AccountType" type="radio" id="AccountType" value="Employee" />
Employee Account</label>
</div></th>
</tr>
<tr>
<th scope="col"><input type="hidden" name="userID" id="userID" value="1" />
<input name="RegistrationDate" type="hidden" id="RegistrationDate" value="1" />
<input name="RegistrationIP" type="hidden" id="RegistrationIP" value="1" /></th>
<th scope="col"><div align="left"></div></th>
</tr>
<tr>
<th scope="col"><label>
<input type="submit" name="Submit" value="Submit" />
</label></th>
<th scope="col"><div align="left">
<label>
<input name="Reset" type="reset" id="Reset" value="Reset" />
</label>
</div></th>
</tr>
</table>
<input type="hidden" name="MM_insert" value="frmRegisterEmployee">
</form>
<p> </p>
<h3> </h3>
</div>
<div id="footer">
Copyright © 2006 Music Connections | Design by <a href="andreasviklund.com">Andreas Viklund</a> | Additional coding by itsnotaproblem </div>
</div>
</body>
</html>
Replies
Replied 16 Aug 2006 11:14:07
16 Aug 2006 11:14:07 Roddy Dairion replied:
What usually causes this error is basically an output happening before the header() funtion. So check in you include script to find out if there's a blank line at the end or an echo or print. If you have anything being displayed before the header() function then this error message will always appear.