Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Warning: Cannot modify header information - headers already sent by 1

Status
Not open for further replies.

aalmeida

MIS
Aug 31, 2000
468
US
after I insert my data into MYSQL I need to redirect to a page that will display the informatio for review and possible updates after validation. But the header() fuction is returning an error:
"Warning: Cannot modify header information - headers already sent by (output started at c:\inetpub\ in c:\inetpub\ on line 61"
<?PHP
$insertGoTo = &quot;confirmation2.php&quot;;
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$insertGoTo .= (strpos($insertGoTo, '?')) ? &quot;&&quot; : &quot;?&quot;;
$insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
}
echo $insertGoTo;
header(sprintf(&quot;Location: %s&quot;, $insertGoTo));//this is Line 61

}
?>

AL Almeida
NT/DB Admin
&quot;May all those that come behind us, find us faithfull&quot;
 
U must not send any output to the browser before u use header().Even a blank space or line before php open tag can casue u this error.
Remove the echo statment before the error line ie
echo $insertGoTo;
and that shd be OK



--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
This will prevent you having that error on that particular page.

(1) ob_start();

(2) ob_end_flush();

write (1) at the top of your PHP page after opening PHP tag and (2) and the bottom before ending PHP tag of the page that causing you error.

Best of luck.
 
Rather than using the buffering functions, it is much better to solve the problem than work around it. Simply remove the echo line. If you're redirecting the user then the user won't see it when the next page comes up anyway.
 
spookie I removed the line and the error no longer show but the FORM variables aren't post to the redirect page.

How to fix that one now?

AL Almeida
NT/DB Admin
&quot;May all those that come behind us, find us faithfull&quot;
 
I am not sure you use the right terminology:

1. When you redirect to a page and append the vars as a querystring you don't POST, it is a GET request.

2. SO you need $_GET or $HTTP_GET_VARS, depending on your PHP version. If you habe PHP > 4.1.2 use the $_GET.

3. You should think about sessions. Redirecting is not the best way, it is time comsuming because you initiate a new request for the redirection. Also the passing of the variables as a GET string is quite obvious and invites manipulation.
 
Ohh men!!

You might just hit on the head, my page is using all $_POST
How dumy I'm

Let me try that and I'll be back to let you know. thanks
you all

AL Almeida
NT/DB Admin
&quot;May all those that come behind us, find us faithfull&quot;
 
Will you be so kind and post that line 65?
 
Yes here it is starting on line 61 where the <?PHP tag starts:

<td height=&quot;500&quot; colspan=&quot;5&quot; valign=&quot;top&quot;><?PHP
//Line 61
IF ((substr(isset($HTTP_POST_VARS[&quot;item_name&quot;]), -3) == 'grp') and (isset($HTTP_POST_VARS[&quot;quantity&quot;]) < 10)) {
echo 'Group rate are available only for groups with more than 10 members,<br> please press the back button of you browser and select the apropriate registration package for you and your group';
}
$price = $_GET[&quot;item_name&quot;]; // Line 65
$numb = $_GET[&quot;quantity&quot;]; // Line 66
if ($numb < 10){
$quantity = 1 ;
}
else {
$quantity = $numb;
}
// This function calculates a total based upon quantity, price, and tax and then returns the results.
function calculate_total ($quantity = 1, $price, $taxrate = .0) {
$total = ($quantity * $price) * ($taxrate + 1);
return number_format ($total, 2);
} // End of calculate_total() function.
echo '<TABLE width=&quot;100%&quot; height=&quot;349&quot; border=&quot;0&quot; cellpadding=&quot;0&quot; cellspacing=&quot;0&quot;>
<TR>
<TD align=&quot;center&quot;><FONT class=&quot;FrmTitle&quot;>Please Verify your Personal Information</FONT></TD>
</TR>
<TR>
<TD><TABLE width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<TR>
<TD width=&quot;12%&quot;><Font class=&quot;items&quot;>Name:</FONT></TD>
<TD colspan=&quot;2&quot;>'.$_GET['first_name'].', '.$_GET['last_name'].'</TD>
</TR>
<TR>
<TD><Font class=&quot;items&quot;>Address:</FONT></TD>
<TD colspan=&quot;2&quot;>'.$_GET['address1'].'</TD>
</TR>
<TR>
<TD><Font class=&quot;items&quot;>City:</FONT></TD>
<TD colspan=&quot;2&quot;>'.$_GET['city'].'</TD>
</TR>
<TR>
<TD><Font class=&quot;items&quot;>State:</FONT></TD>
<TD width=&quot;26%&quot;>'.$_GET['state'].'</TD>
<TD width=&quot;62%&quot;><Font class=&quot;items&quot;>Zip:</FONT>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$_GET['zip'].'</TD>
</TR>
<TR>
<TD><Font class=&quot;items&quot;>Home phone:</FONT></TD>
<TD>('.$_GET['night_phone_a'].') '.$_GET['night_phone_b'].'</TD>
<TD><Font class=&quot;items&quot;>Work phone:</FONT>('.$_GET['day_phone_a'].') '.$_GET['day_phone_b'].'</TD>
</TR>
<TR>
<TD><Font class=&quot;items&quot;>Email:</FONT></TD>
<TD colspan=&quot;2&quot;>'.$_GET['payer_email'].'</TD>
</TR>
</TABLE></TD>
</TR>
<TR>
<TD align=&quot;center&quot;><FONT class=&quot;FrmTitle&quot;>Please Verify your Church Information</FONT></TD>
</TR>
<TR>
<TD><TABLE width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<TR>
<TD width=&quot;12%&quot;><Font class=&quot;items&quot;>Name:</FONT></TD>
<TD colspan=&quot;2&quot;>'.$_GET['c_name'].'</TD>
</TR>
<TR>
<TD><Font class=&quot;items&quot;>Address:</FONT></TD>
<TD colspan=&quot;2&quot;>'.$_GET['c_address'].'</TD>
</TR>
<TR>
<TD><Font class=&quot;items&quot;>City:</FONT></TD>
<TD colspan=&quot;2&quot;>'.$_GET['c_city'].'</TD>
</TR>
<TR>
<TD><Font class=&quot;items&quot;>State:</FONT></TD>
<TD width=&quot;26%&quot;>'.$_GET['c_state'].'</TD>
<TD width=&quot;62%&quot;><Font class=&quot;items&quot;>Zip:</font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;'.$_GET['c_zip'].'</TD>
</TR>
<TR>
<TD><Font class=&quot;items&quot;>Phone:</FONT></TD>
<TD colspan=&quot;2&quot;>'.$_GET['c_phone'].'</TD>
</TR>
</TABLE></TD>
</TR>
<TR>
<TD align=&quot;center&quot;><FONT class=&quot;FrmTitle&quot;>Rates</FONT></TD>
</TR>
<TR>
<TD>
<TABLE width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;0&quot; cellpadding=&quot;0&quot;>
<TR>
<TD colspan=&quot;2&quot; align=&quot;center&quot;><FONT class=&quot;subtitle&quot;>Early by Oct 19 12:00pm - Late after Oct 19 12:00pm</FONT></TD>
</TR>
<TR>
<TD width=&quot;14%&quot;>&nbsp;</TD>
<TD width=&quot;86%&quot;>&nbsp;</TD>
</TR>
<TR>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD>
</TR>
<TR>
<TD>&nbsp;</TD>
<TD>&nbsp;</TD>
</TR>
<TR>
<TD colspan=&quot;2&quot;>&nbsp;</TD>
</TR>
<TR>
<TD colspan=&quot;2&quot;>';

// Main conditional.
if ((is_numeric($quantity)) and (is_numeric($price))) { // Is the quantity a number?

$total = calculate_total ($quantity , $price);
echo &quot;<p>Please Verify that you are purchasing <b>{$quantity}</b> registration(s) at a cost of <b>\${$price}</b> each. With tax, the total comes to <b>\${$total}</b>.</p>\n&quot;;
} else { // Quantity is not a number.'
echo '<p><b>Please enter a valid quantity to purchase!</b></p>';
}
echo '</TD></TR></TABLE></TD></TR>';?>

AL Almeida
NT/DB Admin
&quot;May all those that come behind us, find us faithfull&quot;
 
1. You will want to post your code in [ignore]
Code:
...
[/ignore] tags. The way it's posted now the TGML parser removes all kinds of stuff.

2. Diregegarding #1 it seems that you wrote:
Code:
$price = $_GET&quot;item_name&quot;; // Line 65
    $numb = $_GET&quot;quantity&quot;; // Line 66
### what you need are the square brackets:
$price = $_GET
[
Code:
&quot;item_name&quot;
]
Code:
; // Line 65
$numb = $_GET
[
Code:
&quot;quantity&quot;
]
Code:
; // Line 66
 
I'm sorry I think I misted that I do have the brackets in my code, let me try again:
Code:
IF ((substr(isset($HTTP_POST_VARS[&quot;item_name&quot;]), -3) == 'grp') and (isset($HTTP_POST_VARS[&quot;quantity&quot;]) < 10)) {
	echo 'Group rate are available only for groups with more than 10 members,<br> please press the back button of you browser and select the apropriate registration package for you and your group';
	}
	$price = $HTTP_POST_VARS[&quot;item_name&quot;];
	$numb = $HTTP_POST_VARS[&quot;quantity&quot;];
	if ($numb < 10){
		$quantity = 1 ;
		} 
  	else {
		$quantity = $numb;
		}

AL Almeida
NT/DB Admin
&quot;May all those that come behind us, find us faithfull&quot;
 
I tryed this to see the what was passed:
Code:
print<pre>;
echo 'The get method '.print_r($_GET);
echo 'The post method '.print_r($_POST);

and it returned:

<pre>Array
(
)
the get method 1Array
(
)
the post method 1


AL Almeida
NT/DB Admin
&quot;May all those that come behind us, find us faithfull&quot;
 
With the pasted code you should get a parse error. Anyway...

What is you question now?
 
DRJ478,

I have a form method=&quot;post&quot; the first action is to inserd user data into a mysql database after that foo.php uses the following lines to redirect to bar.php
Code:
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? &quot;&&quot; : &quot;?&quot;;
    $insertGoTo .= $HTTP_SERVER_VARS['QUERY_STRING'];
  }
  //echo $insertGoTo;
  header(sprintf(&quot;Location: %s&quot;, $insertGoTo));
  
}

but bar.php cannot see the form variables

AL Almeida
NT/DB Admin
&quot;May all those that come behind us, find us faithfull&quot;
 
Of course not.
Since you are now using the POST method there will be no querystring. POST passes the variables in the background, not the URL.

You are attempting to pass a non existing querystring.
I recommend that you just include the code of bar.php using an include() statement. There is no real need for redirection here. By keeping everything within the same script you don't have to pass anything.

BTW, are you also posting under the username deecee?
 
nope i'm not deecee althogh I noticed that he had the exact same question I had today so I happened to hop in avoiding creting a new thread for the same thing. I'll accept your advice I'll try it over the weekend and I'll post the results here.


AL Almeida
NT/DB Admin
&quot;May all those that come behind us, find us faithfull&quot;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top