Page 1 of 1

PHP & Header problems??

Posted: Wed May 21, 2003 1:17 pm
by kirkham99
I have removed the "testing displays" PRINT and ECHO that could be generated on the IF SUBMIT code check but still get the following ??

Warning: Cannot add header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\website 9\infodets.php:4) in C:\Program Files\Apache Group\Apache2\htdocs\website 9\infodets.php on line 122

The problem is line 4 does n't do anything really?????

Any ideas?

Code: Select all

<?php 
header("Cache-Control:no-cache"); 
?> 
<?php 
//#Server 
//# $sqlhost = '??'; 
//# $sqluser = '??'; 
//# $sqlpass = '??'; 
//# $sqldb = '??'; 

//#WINdows 
$sqlhost = 'localhost:3306'; 
$sqluser = '??'; 
$sqlpass = '??'; 
$sqldb = 'test'; 
$utable = '??'; 
?> 

<?php 

if ($search) 
{ 
$wher = "email like '%$searchemail%'"; 
include("dump_vars.php"); 
?> 
<FORM name = "searchform2" method="post" action="<?php echo $PHP_SELF?>"> 
<br> 
Search Email : <input type="text" name="searchemail" value="<?php echo $searchemail?>" size="37"> 
<input type="submit" name="search" value="search" > 
</FORM> 

<FORM name = "listdets" method="post" action="infodets.php"> 
 <div align="left" style="width: 613; height: 68"> 
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" bgcolor="#00FFFF" width="710"> 
<tr> 
<td width="58">Id</td> 
<td width="148">First Name</td> 
<td width="95">Last Name</td> 
<td width="115">Email</td> 
<td width="55">List</td> 
<td width="71">Dateadd</td> 
<td width="31">Edit   </td> 
<td width="46">Unsub</td> 
</tr> 
<?php 
#connect to Mysql 
$conn=mysql_connect($sqlhost,$sqluser,$sqlpass) or die("Could not connect to database"); 
$rs=mysql_select_db($sqldb, $conn) or die("Could not select the database"); 

$ucmd = "select * from $utable where $wher"; 
$urow = mysql_query($ucmd) or die("Could not execute the query " . mysql_errno().": ".mysql_error()); 
#$row2 = mysql_fetch_array($urow); 
$cnt = mysql_num_rows($urow); 

echo "Number of rows : $cnt <Br>"; 
$i=0; 
while ($row = mysql_fetch_array($urow)) 
{ 

$fname = $row["fname"]; 
$lname = $row["lname"]; 
$list = $row["list"]; 
$email = $row["email"]; 
$dateadd = $row["dateadd"]; 
$id = $row["id"]; 
$uid = $row["uid"]; 

echo " <tr>"; 
echo " <td> <input type=text name=id[] size=5 value='$id'> </td>"; 
echo " <td width='148'> <input type=text name=fname[] size=20 value='$fname'> </td>"; 
echo " <td width='95'> <input type=text name=lname[] size=20 value='$lname'> </td>"; 
echo " <td width='115'> <input type=text name=email[] size=20 value='$email'> </td>"; 
echo " <td width='55'> <input type=text name=list[] size=5 value='$list'> </td>"; 
echo " <td width='71'> <input type=text name=dateadd[] size=15 value='$dateadd'> </td>"; 
echo " <td width='53'> <input type=checkbox name=opt[$i] value='Edit'> </td>"; 
echo " <td width='46'> <input type=checkbox name=opt[$i] value='Unsub'> </td>"; 
echo " </tr>"; 
$i++;//incr cnt 
} 
?> 

</table> 
<p align="center"> 
<br> 
<input type="submit" name="submit" value="Process the Form" > 
</div> 
</form> 

<?php 
} //endif 

if ($submit) 
{ 
unset($submit); 
//include("dump_vars.php"); 
//process del, edit etc... and re-display 
$i=0; 
$ii=count($fname); 
for($i=0;$i<$ii;$i++) 
{ 
if ( !empty($opt[$i]) ) 
{ 
$conn=mysql_connect($sqlhost,$sqluser,$sqlpass) or die("Could not connect to database"); 
$rs=mysql_select_db($sqldb, $conn) or die("Could not select the database"); 
switch ($opt[$i]) 
{ 
case "Edit": 
$wher = "id = $id[$i]"; 
$ucmd = "update $utable set fname = '$fname[$i]', lname = '$lname[$i]', email = '$email[$i]' where $wher"; 
$urow = mysql_query($ucmd) or die("Could not execute the Update query " . mysql_errno().": ".mysql_error()); 
break; 
case "Unsub": 
$wher = "id = $id[$i] and email = '$email[$i]'"; 
$ucmd = "delete from $utable where $wher"; 
$urow = mysql_query($ucmd) or die("Could not execute the Delete query " . mysql_errno().": ".mysql_error()); 
break; 
}//end case 
}//endif 
} //endfor 

$search = TRUE; 
header("Location:infodets.php"); 
exit (); 
} //endif 
else 
{ 
include("dump_vars.php"); 
?> 
<p> 
<html> 
<head> 
</head> 
<body> 
<FORM name = "searchform" method="post" action="<?php echo $PHP_SELF?>"> 
<input type=hidden name=dosearch value='yes'> 
<br> 
Search Email : <input type="text" name="searchemail" size="37">  
<input type="submit" name="search" value="search" > <br> 
</FORM> 
</body> 
</html> 

<?php 
}
?>
mod_edit: added php tags

second header

Posted: Wed May 21, 2003 3:35 pm
by phpScott
you have a second header that you might be sending down on line 122 as your error states
header("Location:infodets.php");
you can't send anything before you send header information.
Try reworking your code so that there is no raw html being sent before this second header. Outside of the <?php ?> tags

phpScott

Posted: Wed May 21, 2003 7:44 pm
by volka
why do you close and reopen php-tags if there's no output between?
e.g.

Code: Select all

<?php
header("Cache-Control:no-cache");
?>

<?php
header("Content-Type: text/html");
?>
this doesn't work, because there's a newline between the two tags sent directly to the browser, so there's output and the second header doesn't work.
A single whitespace after the first ?> would be enough to cause an error/warning.