Page 1 of 1

header redirecting but included file is not working

Posted: Wed May 06, 2009 1:19 pm
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

Re: header redirecting but included file is not working

Posted: Sat May 09, 2009 6:46 pm
by david64
I can't see this ever getting to step 2, you have hard coded step 1 the redirect in.

Re: header redirecting but included file is not working

Posted: Sat May 09, 2009 10:19 pm
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 ..

Re: header redirecting but included file is not working

Posted: Sat May 09, 2009 10:41 pm
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 :)