Forums
This topic is locked
Header error on redirect after updating record
Posted 22 Jun 2003 12:33:34
1
has voted
22 Jun 2003 12:33:34 Kathlyn Gadd posted:
I have a page (code generated entirely using DWMX PHP server behaviours) that updates a record by reference to that records ID (GET variable - passed using master / detail behaviour). After update the user should be redirected to a 'successful update' page.Unfortunately, the redirect header at line 59 (see below) is causing the following error:
Warning: Cannot modify header information - headers already sent by (output started at /usr/local/psa/home/vhosts/hypermobility.org/httpdocs/edittip.php:12) in /usr/local/psa/home/vhosts/hypermobility.org/httpdocs/edittip.php on line 59
I can't see why the error is happening!
The page code to the start of the html tag is:
<pre id=code><font face=courier size=2 id=code>
<?php
if(!isset($HTTP_COOKIE_VARS['accesslevel'])){
header("Location: login.php"
} else {
if($HTTP_COOKIE_VARS['accesslevel'] < 2){
header("Location: diaryadmin.php"
}
}
?>
<?php require_once('Connections/dbConnection.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 = $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 tips SET category=%s, title=%s, tip=%s, approved=%s WHERE ID=%s",
GetSQLValueString($HTTP_POST_VARS['category'], "int",
GetSQLValueString($HTTP_POST_VARS['title'], "text",
GetSQLValueString($HTTP_POST_VARS['tip'], "text",
GetSQLValueString(isset($HTTP_POST_VARS['approved']) ? "true" : "", "defined","1","0",
GetSQLValueString($HTTP_POST_VARS['ID'], "int");
mysql_select_db($database_dbConnection, $dbConnection);
$Result1 = mysql_query($updateSQL, $dbConnection) or die(mysql_error());
$updateGoTo = "tipadmin_success.php";
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
$updateGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo)); //this is line 59
}
$colname_edittip = "1";
if (isset($HTTP_GET_VARS['ID'])) {
$colname_edittip = (get_magic_quotes_gpc()) ? $HTTP_GET_VARS['ID'] : addslashes($HTTP_GET_VARS['ID']);
}
mysql_select_db($database_dbConnection, $dbConnection);
$query_edittip = sprintf("SELECT * FROM tips, tip_categories WHERE ID = %s AND tip_categories.cat_ID=tips.category", $colname_edittip);
$edittip = mysql_query($query_edittip, $dbConnection) or die(mysql_error());
$row_edittip = mysql_fetch_assoc($edittip);
$totalRows_edittip = mysql_num_rows($edittip);
mysql_select_db($database_dbConnection, $dbConnection);
$query_categories = "SELECT * FROM tip_categories";
$categories = mysql_query($query_categories, $dbConnection) or die(mysql_error());
$row_categories = mysql_fetch_assoc($categories);
$totalRows_categories = mysql_num_rows($categories);
?>
</font id=code></pre id=code>
Any help would be much appreciated!!
NB probably not relevant but I guess I should add that, on submitting the form, the record is correctly updated.
Edited by - katt on 22 Jun 2003 12:48:59
Replies
Replied 22 Jun 2003 14:19:32
22 Jun 2003 14:19:32 Kathlyn Gadd replied:
Problem sorted! - but I thought I would add the solution in case any one else had a similar problem!
There was a hard return between the closing php tag after the login code and the opening tag at the start of the update record code. Once I removed those tags so that the entire php code above the html tag was enclosed in a single set of php script tags - problem solved!
There was a hard return between the closing php tag after the login code and the opening tag at the start of the update record code. Once I removed those tags so that the entire php code above the html tag was enclosed in a single set of php script tags - problem solved!
Replied 17 Jul 2003 22:56:49
17 Jul 2003 22:56:49 Andy Calloway replied:
I've actually taken to doing all my redirects using Javascript since I started getting header errors - much easier.