Forums

PHP

This topic is locked

"Cannot modify header information" problems!!

Posted 13 Aug 2006 00:12:09
1
has voted
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:

&lt;?php require_once('Connections/conn_music.php'); ?&gt;
&lt;?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));
}
?&gt;
&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"&gt;
&lt;html&gt;
&lt;head&gt;
&lt;link rel="stylesheet" type="text/css" href="andreas01.css" media="screen" title="andreas01 (screen)" /&gt;
&lt;link rel="stylesheet" type="text/css" href="print.css" media="print" /&gt;
&lt;title&gt;Music Connections | Register Employee Account&lt;/title&gt;
&lt;link href="css/andreas01.css" rel="stylesheet" type="text/css" /&gt;
&lt;/head&gt;
&lt;body&gt;&lt;div id="wrap"&gt;

&lt;div id="header"&gt;
&lt;h1&gt;Music Connections &lt;/h1&gt;
&lt;/div&gt;
&lt;img id="frontphoto" src="images/front.jpg" width="760" height="175" alt="" /&gt;
&lt;div id="avmenu"&gt;
&lt;h2 class="hide"&gt;Menu:&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;&lt;a href="index.php"&gt;Welcome!&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="register.php"&gt;Register&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="myaccount/index.php"&gt;My Account &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="postjob.php"&gt;Post New Advert &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="viewjobs.php"&gt;View Job Avderts &lt;/a&gt;
&lt;li&gt;&lt;a href="searchjobs.php"&gt;Search Jobs &lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="help.php"&gt;Help/FAQ&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="contact.php"&gt;Contact&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="announce"&gt;
&lt;h3&gt;Latest jobs:&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;&quot;Latest jobs info to appear here.&quot;&lt;/strong&gt;&lt;/p&gt;
&lt;p class="textright"&gt;&lt;a href="index.html"&gt;Read more...&lt;/a&gt;&lt;/p&gt;
&lt;/div&gt;

&lt;/div&gt;

&lt;div id="content"&gt;
&lt;h2&gt;Register employee account &lt;/h2&gt;
&lt;p&gt;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. &lt;/p&gt;

&lt;form action="&lt;?php echo $editFormAction; ?&gt;" id="frmRegisterEmployee" method="POST" name="frmRegisterEmployee"&gt;
&lt;table width="200" border="0" cellpadding="0"&gt;
&lt;tr&gt;
&lt;th class="tables" scope="col"&gt;Name&lt;/th&gt;
&lt;th scope="col"&gt;&lt;label&gt;
&lt;div align="left"&gt;
&lt;input name="Name" type="text" id="Name" /&gt;
&lt;/div&gt;
&lt;/label&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th class="tables" scope="col"&gt;E-Mail Address &lt;/th&gt;
&lt;th scope="col"&gt;&lt;div align="left"&gt;
&lt;label&gt;
&lt;input name="EMail" type="text" id="EMail" /&gt;
&lt;/label&gt;
&lt;/div&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th scope="col"&gt;Address&lt;/th&gt;
&lt;th scope="col"&gt;&lt;div align="left"&gt;
&lt;label&gt;
&lt;textarea name="Address" rows="5" id="Address"&gt;&lt;/textarea&gt;
&lt;/label&gt;
&lt;/div&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th scope="col"&gt;Postcode&lt;/th&gt;
&lt;th scope="col"&gt;&lt;div align="left"&gt;
&lt;label&gt;
&lt;input name="Postcode" type="text" id="Postcode" /&gt;
&lt;/label&gt;
&lt;/div&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th scope="col"&gt;&nbsp;&lt;/th&gt;
&lt;th scope="col"&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th scope="col"&gt;Username&lt;/th&gt;
&lt;th scope="col"&gt;&lt;div align="left"&gt;
&lt;label&gt;
&lt;input name="Username" type="text" id="Username" /&gt;
&lt;/label&gt;
&lt;/div&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th scope="col"&gt;Password&lt;/th&gt;
&lt;th scope="col"&gt;&lt;div align="left"&gt;
&lt;label&gt;
&lt;input name="Password" type="text" id="Password" /&gt;
&lt;/label&gt;
&lt;/div&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th scope="col"&gt;&nbsp;&lt;/th&gt;
&lt;th scope="col"&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th scope="col"&gt;Account Type &lt;/th&gt;
&lt;th scope="col"&gt;&lt;div align="left"&gt;
&lt;label&gt;
&lt;input name="AccountType" type="radio" id="AccountType" value="Employee" /&gt;
Employee Account&lt;/label&gt;
&lt;/div&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th scope="col"&gt;&lt;input type="hidden" name="userID" id="userID" value="1" /&gt;
&lt;input name="RegistrationDate" type="hidden" id="RegistrationDate" value="1" /&gt;
&lt;input name="RegistrationIP" type="hidden" id="RegistrationIP" value="1" /&gt;&lt;/th&gt;
&lt;th scope="col"&gt;&lt;div align="left"&gt;&lt;/div&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;tr&gt;
&lt;th scope="col"&gt;&lt;label&gt;
&lt;input type="submit" name="Submit" value="Submit" /&gt;
&lt;/label&gt;&lt;/th&gt;
&lt;th scope="col"&gt;&lt;div align="left"&gt;
&lt;label&gt;
&lt;input name="Reset" type="reset" id="Reset" value="Reset" /&gt;
&lt;/label&gt;
&lt;/div&gt;&lt;/th&gt;
&lt;/tr&gt;
&lt;/table&gt;


&lt;input type="hidden" name="MM_insert" value="frmRegisterEmployee"&gt;
&lt;/form&gt;
&lt;p&gt;&nbsp;&lt;/p&gt;

&lt;h3&gt;&nbsp;&lt;/h3&gt;
&lt;/div&gt;

&lt;div id="footer"&gt;
Copyright &copy; 2006 Music Connections | Design by &lt;a href="andreasviklund.com"&gt;Andreas Viklund&lt;/a&gt; | Additional coding by itsnotaproblem &lt;/div&gt;

&lt;/div&gt;
&lt;/body&gt;
&lt;/html&gt;

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.

Reply to this topic