Page 1 of 1

redirect after IF statement

Posted: Thu Apr 06, 2006 12:14 pm
by michlcamp
How do I redirect from a form page to a different page (and still keep all my form data) using the IF statement...

what I want to do goes something like this:

Code: Select all

IF ($totalweight = $maxweight)
     {go to https://order_overlimit.php }
I also want to pass hidden fields from my form to the next page...

just one of those things I haven't learned how to do yet....
coming here is always the fastest way...

thanks in advance..
mc

Posted: Thu Apr 06, 2006 1:30 pm
by feyd
  1. store the data into session variables.
  2. call session_write_close()
  3. call header('Location: yourFullURL')
  4. call exit()

Posted: Thu Apr 06, 2006 1:37 pm
by John Cartwright
fyi, your if statement will always evaluate as true since you are using the assignment operator '=' instead of the comparison operator '=='.

I don't know if this was a typo, but I thought I would point it out just incase :wink:

Posted: Thu Apr 06, 2006 9:47 pm
by michlcamp
yes, typo. thanks.

I haven't had much luck with sessions on this site because I'm running all the content through a template page (content.php) with an include in the body

Code: Select all

<?Php Include("$content"); ?>
That seems to mess up the sessions header call -
sometimes yes, sometimes no, and I don't have a good enough handle on sessions yet that I trust it with my customers.

The page I'm working with (in this topic) is an online order page that has already collected customer data but in the event they order more than 150lbs of product, I want them to go to another page where I can do a specific UPS shipping calculation and I want the information they've already entered to follow them there.

there ya have it...

looking for an alternative to sessions, but if that's the best way, that's where I'll end up no doubt. If I drop that page out of the 'include' and create a static html page will that remedy my 'sessions' header errors?

thanks (if you're still around)
mc

Posted: Fri Apr 07, 2006 2:24 am
by RobertGonzalez
You shouldn't have any problems with sessions interaction with includes. You will have problems if you don't use session_start() correctly. Check [url=htp://www.php.net/session_start]the PHP manual for the proper syntax for using sesion_start()[/url] (pay attention to the part about calling it before output to the browser).

Posted: Fri Apr 07, 2006 3:01 am
by Benjamin
Shouldn't this

Code: Select all

IF ($totalweight = $maxweight)
     {go to https://order_overlimit.php }
Be this instead...

Code: Select all

IF (!$totalweight <= $maxweight)
     {go to https://order_overlimit.php }

Posted: Fri Apr 07, 2006 4:12 am
by michlcamp
no, don't think so...

it's:

Code: Select all

$totalweight = $sumweight_all-items;
$maxweight = "150";

if ($totalweight == $maxweight)
    {goto http://order_overlimit.php}