paddyhaig Posted June 3, 2010 Share Posted June 3, 2010 Why am I getting this error when I post to my production server? Warning: Cannot modify header information - headers already sent by (output started at create_staff_member.php:3) in create_staff_member.php on line 56 I am developing on WinXP with WAMP/PHP 5.2.9-2 and my production server is running CentOS with the latest PHP. <?php require_once('../Connections/Concierge.php'); ?> <?php if (!function_exists("GetSQLValueString")) { function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") { if (PHP_VERSION < 6) { $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"] == "form6")) { $insertSQL = sprintf("INSERT INTO auth (first_name, last_name, login, password, privilege) VALUES (%s, %s, %s, %s, %s)", GetSQLValueString($_POST['forename'], "text"), GetSQLValueString($_POST['surname'], "text"), GetSQLValueString($_POST['login'], "text"), GetSQLValueString($_POST['password'], "text"), GetSQLValueString($_POST['priviege'], "text")); mysql_select_db($database_Concierge, $Concierge); $Result1 = mysql_query($insertSQL, $Concierge) or die(mysql_error()); $insertGoTo = "edit_staff_member.php"; if (isset($_SERVER['QUERY_STRING'])) { $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?"; $insertGoTo .= $_SERVER['QUERY_STRING']; } header(sprintf("Location: %s", $insertGoTo)); } mysql_select_db($database_Concierge, $Concierge); $query_Recordset1 = "SELECT * FROM auth"; $Recordset1 = mysql_query($query_Recordset1, $Concierge) or die(mysql_error()); $row_Recordset1 = mysql_fetch_assoc($Recordset1); $totalRows_Recordset1 = mysql_num_rows($Recordset1); ?> <!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>Edit User Details</title> <style type="text/css"> th { color: #FFF; } </style> </head> <body> <div align="center"> <p> </p> <form id="form6" name="form6" method="POST" action="<?php echo $editFormAction; ?>"> <table width="234" border="1" cellpadding="0" cellspacing="0"> <tr bgcolor="#283a86"> <th width="95" scope="row">First Name </th> <td width="133"><input name="forename" type="text" id="forename" size="19" /></td> </tr> <tr bgcolor="#283a86"> <th scope="row">Last Name</th> <td><input name="surname" type="text" id="surname" size="19" /></td> </tr> <tr bgcolor="#283a86"> <th scope="row">User Name</th> <td><input name="login" type="text" id="login" size="19" /></td> </tr> <tr bgcolor="#283a86"> <th scope="row">Password</th> <td><input name="password" type="password" id="password" size="19" /></td> </tr> <tr bgcolor="#283a86"> <th scope="row">Privilege</th> <td><select name="priviege" id="priviege"> <option value="receptionist">Receptionist</option> <option value="manager">Manager</option> <option value="administrator">Administrator</option> <option value="suspended">Suspended</option> </select></td> </tr> </table> <p> <input type="submit" name="submit" id="submit" value="Submit" /> <input type="hidden" name="MM_insert" value="form6" /> </form> </p> </div> </body> </html> <?php mysql_free_result($Recordset1); ?> Quote Link to comment https://forums.phpfreaks.com/topic/203749-cannot-modify-header-information-headers-already-sent-by/ Share on other sites More sharing options...
kenrbnsn Posted June 3, 2010 Share Posted June 3, 2010 Did you read this post? Ken Quote Link to comment https://forums.phpfreaks.com/topic/203749-cannot-modify-header-information-headers-already-sent-by/#findComment-1067142 Share on other sites More sharing options...
PFMaBiSmAd Posted June 3, 2010 Share Posted June 3, 2010 Why am I getting this error when I post to my production server? Because your development system is not setup properly so that the code you write will work on the most common system configurations. Turn output_buffering OFF in your master php.ini (stop and start your web server to get any change made to the master php.ini to take effect.) Make sure that you get the same error as on your live server in case the php.ini that you are changing is not the one that php is using. As to why the output is occurring on line 3 of your file, you likely have 3 blank lines before the <?php tag and they need to be removed from the file because you cannot output any characters to the browser before you send a header to the browser. Quote Link to comment https://forums.phpfreaks.com/topic/203749-cannot-modify-header-information-headers-already-sent-by/#findComment-1067144 Share on other sites More sharing options...
paddyhaig Posted June 3, 2010 Author Share Posted June 3, 2010 Thank you very much, PFMaBiSmAd! You resolved both problems. Quote Link to comment https://forums.phpfreaks.com/topic/203749-cannot-modify-header-information-headers-already-sent-by/#findComment-1067186 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.