Forum Moderators: coopster
The page is loaded with information from a record, which allows the user to change information.
The database is then updated and a new page is called that shows the database content. The database updates successfully, but it fails to load the display page.
It does work on my machine, but not on the website.
The code that is referenced in the errror is:
>>>header(sprintf("Location: %s", $updateGoTo));<<<
This is the code that precedes it:
$updateGoTo = "quotes.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?'))? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
header(sprintf("Location: %s", $updateGoTo));
I'm clueless as to why there are no problems on the local machine, but there is when the page is uploaded.
Still getting the error:
"Cannot modify header information - headers already sent"
Perhaps the code will help.
--------------------------------------------------
<?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!= "")? "'" . date("Y-m-d",strtotime($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_update"])) && ($_POST["MM_update"] == "form1")) {
$updateSQL = sprintf("UPDATE quotes SET subject_pk=%s, author=%s, quote=%s WHERE quote_id=%s",
GetSQLValueString($_POST['subject'], "int"),
GetSQLValueString($_POST['author'], "text"),
GetSQLValueString($_POST['quotes'], "text"),
GetSQLValueString($_POST['hiddenField'], "int"));
mysql_select_db($database_connContest, $connContest);
$Result1 = mysql_query($updateSQL, $connContest) or die(mysql_error());
$updateGoTo = "quotes.php";
if (isset($_SERVER['QUERY_STRING'])) {
$updateGoTo .= (strpos($updateGoTo, '?'))? "&" : "?";
$updateGoTo .= $_SERVER['QUERY_STRING'];
}
/* header(sprintf("Location: %s", $updateGoTo)); */
header("Location: $updateGoTo");
}
$colname_rsQuotes = "1";
if (isset($_GET['quotes_id'])) {
$colname_rsQuotes = (get_magic_quotes_gpc())? $_GET['quotes_id'] : addslashes($_GET['quotes_id']);
}
mysql_select_db($database_connContest, $connContest);
$query_rsQuotes = sprintf("SELECT quotes.quote_id, quotes.subject_pk, quotes.author, quotes.quote, subjects.subject_id, subjects.subject FROM quotes LEFT JOIN subjects ON (quotes.subject_pk = subjects.subject_id) WHERE quotes.quote_id = %s", $colname_rsQuotes);
$rsQuotes = mysql_query($query_rsQuotes, $connContest) or die(mysql_error());
$row_rsQuotes = mysql_fetch_assoc($rsQuotes);
$totalRows_rsQuotes = mysql_num_rows($rsQuotes);
mysql_select_db($database_connContest, $connContest);
$query_rsSubjects = "SELECT * FROM subjects";
$rsSubjects = mysql_query($query_rsSubjects, $connContest) or die(mysql_error());
$row_rsSubjects = mysql_fetch_assoc($rsSubjects);
$totalRows_rsSubjects = mysql_num_rows($rsSubjects);
?>
<!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=iso-8859-1" />
<title>Edit Quotes</title>
<link href="../styles/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="header">Edit Quotes</div>
<?php include('../includes/navigation.inc.php');?>
<div id="content">
<form action="<?php echo $editFormAction;?>" name="form1" id="form1" method="POST">
Author:
<input name="hiddenField" type="hidden" value="<?php echo $row_rsQuotes['quote_id'];?>" />
<input name="author" type="text" id="author" value="<?php echo $row_rsQuotes['author'];?>" size="50" maxlength="50" />
<select name="subject" size="1" id="subject">
<?php
do {
?>
<option value="<?php echo $row_rsSubjects['subject_id']?>"<?php if (!(strcmp($row_rsSubjects['subject_id'], $row_rsQuotes['subject_pk']))) {echo "SELECTED";}?>><?php echo $row_rsSubjects['subject']?></option>
<?php
} while ($row_rsSubjects = mysql_fetch_assoc($rsSubjects));
$rows = mysql_num_rows($rsSubjects);
if($rows > 0) {
mysql_data_seek($rsSubjects, 0);
$row_rsSubjects = mysql_fetch_assoc($rsSubjects);
}
?>
</select>
<br />
<textarea name="quotes" cols="75" rows="25" id="quotes"><?php echo $row_rsQuotes['quote'];?></textarea>
<br />
<input type="submit" name="Submit" value="Submit" />
<input type="hidden" name="MM_update" value="form1">
</form>
</div>
</body>
</html>
<?php
mysql_free_result($rsQuotes);
mysql_free_result($rsSubjects);
?>
Thanks for the input and from your suggestions I did locate the problem.
It turned out that the file submitted was fine. In other words there was no white space. Then I checked the db connection file (the file holding the db info) and there was trailing white space after the closing PHP?>.
What threw me the most was that it was happening only on the remote server and not on the local machine. With the suggestion that CPanel sometimes throws in white space I checked the connection file. There were several trailing blank lines.
Problem gone!