Redirection problem

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

Post Reply
raziel666
Forum Newbie
Posts: 5
Joined: Sat Jul 17, 2004 8:04 am

Redirection problem

Post by raziel666 »

Hi
I'm using a form to insert some data on a database. After the data is inserted I have added an if {} statement (which is working) and I want (depending on the result of the if) to go to some other page. I haven't found any way yet (except one that shows both pages in one - apparently this is not wanted!). Any ideas?
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Check out header() in the php manual. It will show you an exmaple of how to redirect to another page. Just use this to redirect to whichever page you need to.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

:arrow: [php_man]header[/php_man]
kettle_drum
DevNet Resident
Posts: 1150
Joined: Sun Jul 20, 2003 9:25 pm
Location: West Yorkshire, England

Post by kettle_drum »

Oh and if you dont want to use that then you can always use meta tags or javascript.
raziel666
Forum Newbie
Posts: 5
Joined: Sat Jul 17, 2004 8:04 am

Post by raziel666 »

thanks
I'll try with header()
raziel666
Forum Newbie
Posts: 5
Joined: Sat Jul 17, 2004 8:04 am

Post by raziel666 »

I've tried with header() and I get :
Warning: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Group\Apache2\htdocs\add_question.php:2) in C:\Program Files\Apache Group\Apache2\htdocs\add_question.php on line 68

The code near is:
... --> code for inserting data from a form to a database

Code: Select all

<?php	if ($alts ==8)
	{
		header("add_answer_w_5_alt.php");  ----> This is line 68
	}
?>

Any ideas why this might happen?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

you've got text output starting at line 2 of the file C:\Program Files\Apache Group\Apache2\htdocs\add_question.php
User avatar
markl999
DevNet Resident
Posts: 1972
Joined: Thu Oct 16, 2003 5:49 pm
Location: Manchester (UK)

Post by markl999 »

And shouldn't that be header("Location: add_answer_w_5_alt.php");
User avatar
WaldoMonster
Forum Contributor
Posts: 225
Joined: Mon Apr 19, 2004 6:19 pm
Contact:

Post by WaldoMonster »

Code: Select all

<?php
if (some condition)
    {
    echo '<meta http-equiv="refresh" content="0;URL=another_page.php">';
    exit();
    }
?>
The header can only be used before any HTML or other output!
Refresh can be used after some HTML or other output.
Post Reply