header redirecting but included file is not working

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
clem_c_rock
Forum Commoner
Posts: 46
Joined: Mon Jun 07, 2004 9:18 am

header redirecting but included file is not working

Post by clem_c_rock »

Hello, I have a script that is supposed to redirect to the same page but pass a get parameter to flag which partial is included on the page.

The redirect is working and the section where the template is to be included is entered but it's still showing the previous template. It's almost like
the include is getting ignored.

Sample code:

Code: Select all

 
$update = $db->create_update("prescriptions", $_POST, null, "id =". $_POST['prescription_id']);
if($update){ header("Location: prescription.php?step=1"); exit; }
 
include_once(BASE_PATH ."/templates/cpanel/prescription.tmpl.html");
 

and here's the code in the prescription.tmpl.html template:

Code: Select all

 
<body leftmargin="10" topmargin="10" marginwidth="10" marginheight="10">
 
<?php if($step == 1){ echo "INCLUDING TEMPLATE 1 HERE"; include(BASE_PATH ."/templates/cpanel/prescription_1.tmpl.html"); } ?> 
<?php if($step == 2){ include(BASE_PATH ."/templates/cpanel/prescription_2.tmpl.html");  } ?>
 
</body>
</html>
 
 
After the redirect, prescription_2.tmpl.html is still showing even though the if section where prescription_1.tmpl.html is to be included is entered.

Very strange - any ideas?

Thanks,
Clem C
Last edited by Benjamin on Sun May 10, 2009 12:33 pm, edited 1 time in total.
Reason: Changed code type from text to php.
david64
Forum Commoner
Posts: 53
Joined: Sat May 02, 2009 8:12 am
Location: Wales

Re: header redirecting but included file is not working

Post by david64 »

I can't see this ever getting to step 2, you have hard coded step 1 the redirect in.
mdk999
Forum Newbie
Posts: 22
Joined: Fri May 08, 2009 3:21 pm

Re: header redirecting but included file is not working

Post by mdk999 »

in the second section does $step = ..

Code: Select all

$step = isset($_GET['step'])?$_GET['step']:false; //sets the step variable..
if not you can put that above the lines and it should work ..
Last edited by Benjamin on Sun May 10, 2009 12:34 pm, edited 1 time in total.
Reason: Changed code type from text to php.
mickd
Forum Contributor
Posts: 397
Joined: Tue Jun 21, 2005 9:05 am
Location: Australia

Re: header redirecting but included file is not working

Post by mickd »

I'm not sure if i understood it completely (because maybe you had another reason to), but couldn't you just do this?

Code: Select all

 
if($update) {
   $step = 1;
}
 
Instead of redirecting them back to the same page (which if $update always returned true, it would be in a loop?), and just setting the variable without the redirect.

Though you might of had your reason :)
Post Reply