redirect after IF statement

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
michlcamp
Forum Commoner
Posts: 78
Joined: Mon Jul 18, 2005 11:06 pm

redirect after IF statement

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

  1. store the data into session variables.
  2. call session_write_close()
  3. call header('Location: yourFullURL')
  4. call exit()
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post 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:
michlcamp
Forum Commoner
Posts: 78
Joined: Mon Jul 18, 2005 11:06 pm

Post 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
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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).
User avatar
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post 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 }
michlcamp
Forum Commoner
Posts: 78
Joined: Mon Jul 18, 2005 11:06 pm

Post 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}
Post Reply