Forum Moderators: coopster
My problem is this, i'm trying to add the on submit code to the header, when i do the table does not update.
If i have the on submit code after the loop the table updates fine but i get the headers already send spiel, i'm sure it's one tiny thing that's causing the problem, but i'm really struggling to find it.
heres the code
$tbl_name = "display_tasks"; // Table name$sql="SELECT * FROM $tbl_name";
$result=mysql_query($sql);
// Count table rows
$count=mysql_num_rows($result);
if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {
for($i=0;$i<$count;$i++){
$sql1="UPDATE $tbl_name SET task_deadline='$task_deadline[$i]', title='$title[$i]' WHERE number='$number[$i]'";
$result1=mysql_query($sql1);
}
}
if($result1){
header("location:home.php");
}
mysql_close();
...................
//in the body
<?php
while($rows=mysql_fetch_array($result)){
?>
<tr>
<td align="left"><? $number[]=$rows['number'];?><? echo $rows['number'];?></td>
<td align="left"><? echo $rows['username'];?></td>
<td align="left"><input name="task_deadline[]" type="text" id="task_deadline" value="<? echo $rows['task_deadline'];?>"></td>
<td align="left"><input name="title[]" type="text" id="title" value="<? echo $rows['title'];?>"></td>
</tr>
<?php
}
?>
<?php
// table updates fine when the form submit code is here - but get headers already sent stuff
?>
thanks for looking
mat
I can't for the life of me see why this should'nt work up in the header.
It's all in the logic. You cannot use the header() function if you have already "written" information out to the browser. Not even a blank space. So your logic may look something like this instead ...
if (submit was pressed) {
// process my update
// close sql connection
// redirect user with the header()
}
/**
* otherwise,
* 1) SELECT your data
* 2) prepare your browser output
* 3) close sql connection
*/