PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
nite4000
Forum Contributor
Posts: 209 Joined: Sun Apr 12, 2009 11:31 am
Post
by nite4000 » Fri Oct 09, 2009 1:00 pm
Hey I need to get this form code to work. I need it to redirect a user to a different page according to what they select in the drop box.
Here is the code
Code: Select all
$_SESSION['manual.php'] = true;
if (strlen($_POST['go'])) {
if ($_POST['paypro'] == 'LR')
{
$location = "lr_form.php";
}
if ($_POST['paypro'] == 'PM')
{
$location = "pm_form.php";
}
header ("Location: $location");
} else {
$_SESSION['manual.php'] = false;
}
I am not sure why it wont work i get a error msgs about cannot send header information
hope someone can help
Thanks
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Fri Oct 09, 2009 1:13 pm
Is there any output before the error message?
nite4000
Forum Contributor
Posts: 209 Joined: Sun Apr 12, 2009 11:31 am
Post
by nite4000 » Fri Oct 09, 2009 1:31 pm
what kind of out put? I may not know it as a out put so you will have to give me an example
jackpf
DevNet Resident
Posts: 2119 Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK
Post
by jackpf » Fri Oct 09, 2009 1:50 pm
As in, is there anything on the page before the error message??
nite4000
Forum Contributor
Posts: 209 Joined: Sun Apr 12, 2009 11:31 am
Post
by nite4000 » Fri Oct 09, 2009 2:02 pm
no only when i try to execute teh code after pressing the button
desperado
Forum Commoner
Posts: 46 Joined: Wed Dec 10, 2008 8:49 am
Post
by desperado » Fri Oct 09, 2009 2:48 pm
if there is there *any* whitespace, carriage return, html..... in your file before your script, you will get that error.
Code: Select all
<?php
$_SESSION['manual.php'] = true;
if (strlen($_POST['go'])) {
if ($_POST['paypro'] == 'LR')
{
$location = "lr_form.php";
}
if ($_POST['paypro'] == 'PM')
{
$location = "pm_form.php";
}
header ("Location: $location");
} else {
$_SESSION['manual.php'] = false;
}
?>
the above would be ok, whereas below is not:
Code: Select all
<html> [color=#80BF40]<--notice this?[/color]
<head> [color=#80BF40]<--notice this?[/color]
[color=#80BF40]<--notice this?[/color]
<?php
$_SESSION['manual.php'] = true;
if (strlen($_POST['go'])) {
if ($_POST['paypro'] == 'LR')
{
$location = "lr_form.php";
}
if ($_POST['paypro'] == 'PM')
{
$location = "pm_form.php";
}
header ("Location: $location");
} else {
$_SESSION['manual.php'] = false;
}
?>
nite4000
Forum Contributor
Posts: 209 Joined: Sun Apr 12, 2009 11:31 am
Post
by nite4000 » Fri Oct 09, 2009 3:05 pm
This is the error when i try it
Warning: Cannot modify header information - headers already sent by (output started at /home/surf/public_html/memheader.php:4) in /home/surf/public_html/members/manual.php on line 35
line 35 is this
which is part of
Code: Select all
header ("Location: $location");
} else {
$_SESSION['manual.php'] = false;
}
any ideas?
desperado
Forum Commoner
Posts: 46 Joined: Wed Dec 10, 2008 8:49 am
Post
by desperado » Fri Oct 09, 2009 3:15 pm
please re-read my previous post above. your script is probably an include within other files, therefore you have something before it is called.
nite4000
Forum Contributor
Posts: 209 Joined: Sun Apr 12, 2009 11:31 am
Post
by nite4000 » Fri Oct 09, 2009 3:19 pm
yeah i see what the problem is so there isnt no other way I can have it do what i want without using the header redirection?
desperado
Forum Commoner
Posts: 46 Joined: Wed Dec 10, 2008 8:49 am
Post
by desperado » Fri Oct 09, 2009 3:23 pm
why not just leave it by itself and have the form target "members/manual.php" directly, instead of the page where it is included?
the redirect will be instantanious, and you'll never notice you were on a page with no header and footer...