Jump to content

PHP Header Problem


kpetsche20

Recommended Posts

I think there might be a problem with my header syntax, everytime I try to run this code I get this error

 

 

Warning: Cannot modify header information - headers already sent by (output started at /home1/bestones/public_html/gbclogin/members/index.php:17) in /home1/bestones/public_html/gbclogin/members/agreements.php on line 42

 

I get the errors on all the lines with the header code.

 

 

 

if($_GET['id'] == 1)	{
			$var = 0;
			mysql_query("UPDATE users SET agree". $var ."sig='$sigcode', agree". $var ."='1', agree".$var."date='$_POST[date]' where login='".$_POST['id']."'") or die(mysql_error());
			header("Location:index.php?p=agreements");
		} elseif($_GET['id'] == 2)	{
			$var = 1;

			if($_POST['page'] == '1')	{
				mysql_query("UPDATE users SET agree".$var."effdate='{$_POST['agree1effdate']}', agree".$var."bus='{$_POST['agree1bus']}', agree".$var."loc='{$_POST['agree1loc']}', agree".$var."i1='{$sigcode}' where login='".$_POST['id']."'") or die(mysql_error());
				header("Location:index.php?p=agreements&a=edit&id=2&page=2");
			} elseif($_REQUEST['page'] == 2)	{
				mysql_query("UPDATE users SET agree".$var."i2='{$sigcode}' where login='".$_POST['id']."'") or die(mysql_error());
				header("Location:index.php?p=agreements&a=edit&id=2&page=3");

Link to comment
https://forums.phpfreaks.com/topic/106811-php-header-problem/
Share on other sites

Not that I noticed.

 

Here is the whole code to the page.

 

<?php 


if ($_GET['a'] == "edit")	{
$new=mysql_fetch_array(mysql_query("SELECT * FROM agreements WHERE `id`='$_GET[id]'"));
$useragree=mysql_fetch_array(mysql_query("SELECT * FROM users WHERE login = '$_SESSION[login]'")) or die (mysql_error());

if ($_POST['id'] == false)	{
	if ($useragree['agree'.$_GET[id]-1] == 0)	{
		echo $new['name'];
		$newvar=false;
		include($new['url']);
	}
} else	{
	$numcoordinates = explode(" ", $_POST['signature']);
	$numcor = count($numcoordinates);

	$thick = 0;

	if ($numcor <= 2) {
		echo "<br><p align='center'><h2>You must sign in the signbox prior to submitting.<br>
		Click the button below to return to signbox.</h2>
		<FORM>
		<INPUT TYPE='button' VALUE='BACK' 
		onClick='history.go(-1)'>
		</FORM>";

	} else {
		@include 'trialsigproc2.php';
		$newdirname = "agrees/signatures/".$_POST['name'];
		$sigcode = "$newdirname/signature.png";

		if($_GET['id'] == 1)	{
			$var = 0;
			mysql_query("UPDATE users SET agree". $var ."sig='$sigcode', agree". $var ."='1', agree".$var."date='$_POST[date]' where login='".$_POST['id']."'") or die(mysql_error());

		} elseif($_GET['id'] == 2)	{
			$var = 1;

			if($_POST['page'] == '1')	{
				mysql_query("UPDATE users SET agree".$var."effdate='{$_POST['agree1effdate']}', agree".$var."bus='{$_POST['agree1bus']}', agree".$var."loc='{$_POST['agree1loc']}', agree".$var."i1='{$sigcode}' where login='".$_POST['id']."'") or die(mysql_error());
				header("Location:index.php?p=agreements&a=edit&id=2&page=2");
			} elseif($_REQUEST['page'] == 2)	{
				mysql_query("UPDATE users SET agree".$var."i2='{$sigcode}' where login='".$_POST['id']."'") or die(mysql_error());
				header("Location:index.php?p=agreements&a=edit&id=2&page=3");
			} elseif($_REQUEST['page'] == 3)	{
				mysql_query("UPDATE users SET agree". $var ."sig='$sigcode', agree". $var ."='1', agree".$var."date='$_POST[date]', agree".$var."title='{$_POST['agree1title']}', agree".$var."print='{$_POST['agree1print']}', agree".$var."company='{$_POST['agree1company']}' where login='".$_POST['id']."'") or die(mysql_error());
				header("Location:index.php?p=agreements");
			}
		} elseif($_GET['id'] == 3)	{
			$var = 2;

			if($_POST['page'] == '1')	{
				mysql_query("UPDATE users SET agree".$var."effdate='{$_POST['agree2effdate']}', agree".$var."i1='{$sigcode}' where login='".$_POST['id']."'") or die(mysql_error());
				header("Location:index.php?p=agreements&a=edit&id=3&page=2");
			} elseif($_REQUEST['page'] == 2)	{
				mysql_query("UPDATE users SET agree".$var."i2='{$sigcode}' where login='".$_POST['id']."'") or die(mysql_error());
				header("Location:index.php?p=agreements&a=edit&id=3&page=3");
			} elseif($_REQUEST['page'] == 3)	{
				mysql_query("UPDATE users SET agree".$var."i3='{$sigcode}' where login='".$_POST['id']."'") or die(mysql_error());
				header("Location:index.php?p=agreements&a=edit&id=3&page=4");
			} elseif($_REQUEST['page'] == 4)	{
				mysql_query("UPDATE users SET agree".$var."i4='{$sigcode}', agree".$var."fax='{$_POST['agree2fax']}', agree".$var."address='{$_POST['agree2address']}', agree".$var."attn='{$_POST['agree2attn']}', agree".$var."ph='{$_POST['agree2ph']}' where login='".$_POST['id']."'") or die(mysql_error());
				header("Location:index.php?p=agreements&a=edit&id=3&page=5");
			} elseif($_REQUEST['page'] == 5)	{
				mysql_query("UPDATE users SET agree". $var ."sig='$sigcode', agree".$var."tax='{$_POST['agree2tax']}', agree". $var ."='1', agree".$var."date='$_POST[date]',  agree".$var."title='{$_POST['agree2title']}', agree".$var."print='{$_POST['agree2print']}' where login='".$_POST['id']."'") or die(mysql_error());
				header("Location:index.php?p=agreements");
			}
		}
	}
}
} elseif ($_GET['a'] == "view")	{
$new=mysql_fetch_array(mysql_query("SELECT * FROM agreements WHERE `id`='$_GET[id]'"));
$useragree=mysql_fetch_array(mysql_query("SELECT * FROM users WHERE login = '$_SESSION[login]'")) or die (mysql_error());
echo $new['name'];
$newvar=true;
include($new['url']);
} else	{
?>

<strong>Unsigned Agreements</strong>
<table width="600" border="0" cellpadding="3" cellspacing="1" >
      	<tr><td>Name</td><td> </td></tr>
	<?php
	$new=mysql_query("SELECT * FROM agreements");
	$useragree=mysql_fetch_array(mysql_query("SELECT * FROM users WHERE login = '$_SESSION[login]'")) or die (mysql_error());
	for($i=0;$i<=3;$i++){
	$data=mysql_fetch_array($new);
	if ($useragree['agree'.$i] == '0'){
	echo "<tr><td>$data[name]</td><td><a href='index.php?p=agreements&a=edit&id=$data[id]'>View</a></td></tr>";}}
	?></table>
<strong>Signed Agreements</strong>
<table width="600" border="0" cellpadding="3" cellspacing="1">
<tr><td>Name</td><td> </td></tr>
<?  $new=mysql_query("SELECT * FROM agreements");
	$useragree=mysql_fetch_array(mysql_query("SELECT * FROM users WHERE login = '$_SESSION[login]'")) or die (mysql_error());
	for($i=0;$i<=3;$i++){
	$data=mysql_fetch_array($new);
	if ($useragree['agree'.$i]){
	echo "<tr><td>$data[name]</td><td><a href='index.php?p=agreements&a=view&id=$data[id]'>View</a></td></tr>";}}
	?>
	</table> <?}?>

Link to comment
https://forums.phpfreaks.com/topic/106811-php-header-problem/#findComment-547558
Share on other sites

You can't use echo before header(). Logically in your code you shouldn't be echoing anything to the screen in the first place if there is a possibility the user could be redirected to another page.

 

You should put an exit; call after your header functions as well.

Link to comment
https://forums.phpfreaks.com/topic/106811-php-header-problem/#findComment-547650
Share on other sites

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.