Jump to content

Warning: Cannot modify header information - headers already sent by


andrew_ww

Recommended Posts


I'll try again:

[code]<?php
// Get MySQL connection
require_once('../required/conn.php');
// Begin session
if (!isset($_SESSION)) {
  session_start();
}
// If user session is not set redirect to login page
if(!isset($_SESSION['authenticated'])) {
          header("location: ../?notification=pleaselogin");
}
// Logout link
$logout = $_SERVER['PHP_SELF']."?begone=true";
// If user chooses to logout unset session and redirect
if(isset($_REQUEST['begone']) && $_REQUEST['begone'] == true) {
    $_SESSION['authenticated'] = NULL;
    unset($_SESSION['authenticated']);
    header("location: ../index.php?notification=loggedout");
}
// Get user's ID from session
$userID = $_SESSION['authenticated'];
?>
<?php require_once('../Connections/db.php'); ?>
<?php
$IP_LOG = $_SERVER["REMOTE_ADDR"];
$HOSTNAME_LOG = gethostbyaddr($_SERVER['REMOTE_ADDR']);
?>



<?php
$colname_rs_table1 = "1";
if (isset($_GET['recordID'])) {
  $colname_rs_table1 = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
}
mysql_select_db($database_db, $db);
//$query_rs_table1 = sprintf("SELECT * FROM tbl_table1 INNER JOIN table2 ON (tbl_table1.id = table2.id) WHERE table2.id = %s", $colname_rs_table1);
$query_rs_table1 = sprintf("SELECT * FROM table2 WHERE table2.id = %s", $colname_rs_table1);
$rs_table1 = mysql_query($query_rs_table1, $DII) or die(mysql_error());
$row_rs_table1 = mysql_fetch_assoc($rs_table1);
$totalRows_rs_table1 = mysql_num_rows($rs_table1);
?>

<?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_update"])) && ($_POST["MM_update"] == "form1")) {
  $updateSQL = sprintf("UPDATE table2 SET sub=%s WHERE id=%s",
                      GetSQLValueString($_POST['sub'], "text"),
                      GetSQLValueString($_POST['id'], "int"));

  mysql_select_db($database_db, $db);
  $Result1 = mysql_query($updateSQL, $db) or die(mysql_error());

  $updateGoTo = "index.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $updateGoTo .= (strpos($updateGoTo, '?')) ? "&" : "?";
    $updateGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $updateGoTo));
}
?> [/code]
which line is the header being sent by....

The only reason to get this error is that your code is outputting to the browser before you are trying to do the header call. Make sure you are not echoing anything, or no other html is being outputted. OR wrap the whole thing in ob_start() at the beginning, and ob_end_flush() at the bottom.

also did you read this

http://www.phpfreaks.com/forums/index.php/topic,37442.0.html

It is on the main page of php help titled HEADER ERRORS - READ HERE BEFORE POSTING THEM

the whitespace in your script would be where it goes

[code=php:0]
// php here
?>



<?php
// more stuff
[/code]

that stuff in between is white space that is outputted to the browser.

just remove them!

[code=php:0]
// php here

// more stuff
[/code]
Yes, ob_start and ob_end_flush are acceptable, however I agree with genericnumber1 , since all the code is php just have a <?php to start and ?> to end  you are starting and ending php several times

[code]$HOSTNAME_LOG = gethostbyaddr($_SERVER['REMOTE_ADDR']);
?>
//whitespace
//whitespace
//whitespace
<?php
$colname_rs_table1 = "1";[/code]
[code]
?>
//whitespace
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{[/code]

remove those whitespace lines and your code should be golden

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.