Forums

PHP

This topic is locked

Cannot modify header information

Posted 11 Apr 2003 14:57:12
1
has voted
11 Apr 2003 14:57:12 Mick Warnes posted:
I have a MySQL database that is being manipulated by PHP and using MX to create the pages. All seems to work well, except when updating a record. Although the record is updating an error is displayed at the top of the page.

Warning: Cannot modify header information - headers already sent by (output started at D:\Intranet\vintranet\people\admin_edit.php:2) in D:\Intranet\vintranet\people\admin_edit.php on line 61

Line 61 0f this file is "header(sprintf("Location: %s", $updateGoTo));"

Is this a MySQL issue or PHP and if so how do I get around it.

Thank you in anticipation.

Mick

Replies

Replied 11 Apr 2003 16:09:04
11 Apr 2003 16:09:04 Brent Colflesh replied:
Move the update code block above any header output code manually in code view.

Regards,
Brent

Replied 14 Apr 2003 15:37:00
14 Apr 2003 15:37:00 Mick Warnes replied:
Thanks for the reply Brent.

I'm a bit new to scripting and started to move code about with a certain amount of naivity. However eventually the error stopped happening. So I went to do an insertion page and got the original error. I have compared the two files and find no difference except for 'INSERT INTO' and 'UPDATE table_name SET'.
I don't think I have learned anything here as I have a file working without knowing how and I can't get the other one working through ignorance.

If you could explain I would be grateful.

Code for edit:
<pre id=code><font face=courier size=2 id=code>&lt;?php require_once('../Connections/connPeople.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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_update"])) && ($HTTP_POST_VARS["MM_update"] == "form1") {
$updateSQL = sprintf("UPDATE people SET lastName=%s, firstName=%s, site=%s, location=%s, department=%s, jobTitle=%s, ext=%s, ddi=%s, vehicle1=%s, reg1=%s, vehicle2=%s, reg2=%s, vehicle3=%s, reg3=%s, photo=%s, firepoint=%s WHERE id=%s",
GetSQLValueString($HTTP_POST_VARS['lastName'], "text",
GetSQLValueString($HTTP_POST_VARS['firstName'], "text",
GetSQLValueString($HTTP_POST_VARS['site'], "text",
GetSQLValueString($HTTP_POST_VARS['location'], "text",
GetSQLValueString($HTTP_POST_VARS['department'], "text",
GetSQLValueString($HTTP_POST_VARS['jobTitle'], "text",
GetSQLValueString($HTTP_POST_VARS['ext'], "text",
GetSQLValueString($HTTP_POST_VARS['ddi'], "text",
GetSQLValueString($HTTP_POST_VARS['vehicle1'], "text",
GetSQLValueString($HTTP_POST_VARS['reg1'], "text",
GetSQLValueString($HTTP_POST_VARS['vehicle2'], "text",
GetSQLValueString($HTTP_POST_VARS['reg2'], "text",
GetSQLValueString($HTTP_POST_VARS['vehicle3'], "text",
GetSQLValueString($HTTP_POST_VARS['reg3'], "text",
GetSQLValueString($HTTP_POST_VARS['photo'], "text",
GetSQLValueString($HTTP_POST_VARS['firepoint'], "text",
GetSQLValueString($HTTP_POST_VARS['id'], "int");

mysql_select_db($database_connPeople, $connPeople);
$Result1 = mysql_query($updateSQL, $connPeople) or die(mysql_error());

$updateGoTo = "success.htm";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
}

$colname_rsPersonnel = "1";
if (isset($HTTP_GET_VARS['peopleID'])) {
$colname_rsPersonnel = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['peopleID'] : addslashes($HTTP_GET_VARS['peopleID']);
}
mysql_select_db($database_connPeople, $connPeople);
$query_rsPersonnel = sprintf("SELECT * FROM people WHERE lastName = '%s'", $colname_rsPersonnel);
$rsPersonnel = mysql_query($query_rsPersonnel, $connPeople) or die(mysql_error());
$row_rsPersonnel = mysql_fetch_assoc($rsPersonnel);
$totalRows_rsPersonnel = mysql_num_rows($rsPersonnel);
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Vislink Personnel Results&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;link href="../vintranet.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;
&lt;body width="600" marginheight=0 marginwidth=0 leftmargin=0 topmargin=0&gt;
&lt;table width="100%" border="0" cellpadding="0" cellspacing="5"&gt;...... </font id=code></pre id=code>

Add file:
<pre id=code><font face=courier size=2 id=code>&lt;?php require_once('../Connections/connPeople.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 = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1") {
$insertSQL = sprintf("INSERT INTO people (lastName, firstName, site, location, department, jobTitle, ext, ddi, vehicle1, reg1, vehicle2, reg2, vehicle3, reg3, photo, firepoint) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['lastName'], "text",
GetSQLValueString($HTTP_POST_VARS['firstName'], "text",
GetSQLValueString($HTTP_POST_VARS['site'], "text",
GetSQLValueString($HTTP_POST_VARS['location'], "text",
GetSQLValueString($HTTP_POST_VARS['department'], "text",
GetSQLValueString($HTTP_POST_VARS['jobTitle'], "text",
GetSQLValueString($HTTP_POST_VARS['ext'], "text",
GetSQLValueString($HTTP_POST_VARS['ddi'], "text",
GetSQLValueString($HTTP_POST_VARS['vehicle1'], "text",
GetSQLValueString($HTTP_POST_VARS['reg1'], "text",
GetSQLValueString($HTTP_POST_VARS['vehicle2'], "text",
GetSQLValueString($HTTP_POST_VARS['reg2'], "text",
GetSQLValueString($HTTP_POST_VARS['vehicle3'], "text",
GetSQLValueString($HTTP_POST_VARS['reg3'], "text",
GetSQLValueString($HTTP_POST_VARS['photo'], "text",
GetSQLValueString($HTTP_POST_VARS['firepoint'], "text");

mysql_select_db($database_connPeople, $connPeople);
$Result1 = mysql_query($insertSQL, $connPeople) or die(mysql_error());

$insertGoTo = "success.htm";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $insertGoTo));
}

$colname_rsPersonnel = "1";
if (isset($HTTP_GET_VARS['peopleID'])) {
$colname_rsPersonnel = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['peopleID'] : addslashes($HTTP_GET_VARS['peopleID']);
}
mysql_select_db($database_connPeople, $connPeople);
$query_rsPersonnel = sprintf("SELECT * FROM people WHERE lastName = '%s'", $colname_rsPersonnel);
$rsPersonnel = mysql_query($query_rsPersonnel, $connPeople) or die(mysql_error());
$row_rsPersonnel = mysql_fetch_assoc($rsPersonnel);
$totalRows_rsPersonnel = mysql_num_rows($rsPersonnel);
?&gt;
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;Vislink Personnel Results&lt;/title&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"&gt;
&lt;link href="../vintranet.css" rel="stylesheet" type="text/css"&gt;
&lt;/head&gt;


&lt;body width="600" marginheight=0 marginwidth=0 leftmargin=0 topmargin=0&gt;
&lt;table width="100%" border="0" cellpadding="0" cellspacing="5"&gt; </font id=code></pre id=code>
Replied 17 Apr 2003 14:04:06
17 Apr 2003 14:04:06 Mick Warnes replied:
I've found the problem, WHITESPACE!

I saw someone else was having this sort of error on a PHP forum and in the course of solving this complaint the 'Whitespace' issue came up.

There was simply one empty character between the end of the first line of code and the beginning of the second. I deleted this and it got rid of my error.

If anyone can explain WHY this is, I would be grateful.

Mick
Replied 10 May 2006 19:38:01
10 May 2006 19:38:01 Ron Jonk replied:
Sometimes dreamweaver (8 on my mac) adds extra whitepace you don't see <img src=../images/dmxzone/forum/icon_smile_sad.gif border=0 align=middle>
when I have this problem and copy and paste the source in textedit and convert the text to plain text and save it again the problem disappears. How don't ask me but there is probabiy a character added i don't see in dreamweaver

Reply to this topic