Page 1 of 1

header error

Posted: Fri Mar 31, 2006 2:16 pm
by Cateyes
I am having a strange hiccup I can update the record but this bounces back to me Warning: Cannot modify header information - headers already sent by (output started at c:\xxx\xxxx\edit_student.php:14) in c:\xxx\xxxx\edit_student.php on line 65

I have tried just running the program from without the other oage forwarding the data and still the problem I cannot see where the problem is. Here is the code.

Code: Select all

<?php require_once('../xxxx/xxxx.php'); ?>
<?php 
$c=0;
$m=0;
?>
<?php
mysql_select_db($database_xxxx, $xxxx);
$query_rs_program = "SELECT * FROM student_catagorys";
$rs_program = mysql_query($query_rs_program, $xxxx) or die(mysql_error());
$row_rs_program = mysql_fetch_assoc($rs_program);
$totalRows_rs_program = mysql_num_rows($rs_program);
?>
<?php do { ?>
  <?php $cat[$c] = $row_rs_program['catagory']; ?>
  <?php $c=$c+1; ?>
  <?php } while ($row_rs_program = mysql_fetch_assoc($rs_program)); ?>
<?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 student_accounts SET first_name=%s, last_name=%s, user_name=%s, password=%s, catagory=%s WHERE id=%s",
                       GetSQLValueString($_POST['firstname'], "text"),
                       GetSQLValueString($_POST['lastname'], "text"),
                       GetSQLValueString($_POST['username'], "text"),
                       GetSQLValueString($_POST['password'], "text"),
                       GetSQLValueString($_POST['program'], "text"),
                       GetSQLValueString($_POST['hiddenField'], "int"));

  mysql_select_db($database_NWRC, $NWRC);
  $Result1 = mysql_query($updateSQL, $NWRC) or die(mysql_error());

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

$colname_rs_student = "-1";
if (isset($_GET['recordID'])) {
  $colname_rs_student = (get_magic_quotes_gpc()) ? $_GET['recordID'] : addslashes($_GET['recordID']);
}
mysql_select_db($database_xxxx, $xxxx);
$query_rs_student = sprintf("SELECT * FROM student_accounts WHERE id = %s", $colname_rs_student);
$rs_student = mysql_query($query_rs_student, $xxxx) or die(mysql_error());
$row_rs_student = mysql_fetch_assoc($rs_student);
$totalRows_rs_student = mysql_num_rows($rs_student);
?><!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>Untitled Document</title>
</head>

<body>
<form id="form1" name="form1" method="POST" action="<?php echo $editFormAction; ?>">
  <table width="663" border="0">
    <tr>
      <td width="71" nowrap="nowrap">Last Name </td>
      <td width="72" nowrap="nowrap">First Name </td>
      <td width="61" nowrap="nowrap">Username</td>
      <td width="60" nowrap="nowrap">Password</td>
      <td width="377" nowrap="nowrap">Program</td>
    </tr>
    <tr>
      <td valign="top"><label>
        <input name="lastname" type="text" id="lastname" value="<?php echo $row_rs_student['last_name']; ?>" />
      </label></td>
      <td valign="top"><label>
        <input name="firstname" type="text" id="firstname" value="<?php echo $row_rs_student['first_name']; ?>" />
      </label></td>
      <td valign="top"><?php echo $row_rs_student['user_name']; ?></td>
      <td valign="top"><?php echo $row_rs_student['password']; ?></td>
      <td valign="top"><label>
        <select name="program" id="program">
		<?php 
			while($m<$c)
			{
			if($m<1)
				{
				echo "<option value='".$row_rs_student['catagory']."'>".$row_rs_student['catagory']."</option>";
				}
			echo "<option value='".$cat[$m]."'>".$cat[$m]."</option>";
			$m=$m+1;
			} ?>
        </select>
      </label></td>
    </tr>
  </table>
  <input name="username" type="hidden" id="username" value="<?php echo $row_rs_student['user_name']; ?>" />
  <input name="password" type="hidden" id="password" value="<?php echo $row_rs_student['password']; ?>" />
  <input name="hiddenField" type="hidden" value="<?php echo $row_rs_student['id']; ?>" />
<p>
    <label>
    <input type="submit" name="Submit" value="Update" />
    </label>
  </p>
<input type="hidden" name="MM_update" value="form1">
</form>
</body>
</html>
<?php
mysql_free_result($rs_student);

mysql_free_result($rs_program);
?>
I am sure its something simple just cant see it throught the fog(have flu :))

Posted: Fri Mar 31, 2006 2:50 pm
by jwalsh
You cannot send headers after output has been sent. I believe this is caused because of the multiple PHP tags with line breaks between them.

Posted: Fri Mar 31, 2006 6:48 pm
by Cateyes
well all I did was take out all the php stop and starts as I added coded I had it in its own code but by removing

Code: Select all

?>
<?php
and that fixed the headache.