Need help "traveling" between pages

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
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

Need help "traveling" between pages

Post by bwv2 »

Hi,
This may seem like an elementary problem, and I would surely be shunned from the "cool kids" group if I asked anyone I know. I have no web programming experience and am trying to teach myself php. Now that you know where I'm coming from, here is my question...

My website consists of several "steps" that gather input from the user. In each step, variables are created from the form input. In the end, all of the variables are used in math equations to produce some end result that is reported to the user. Each "step" is to be a new page, so the user is kind of led through a series of form-rittled pages ending in eudamonia and eternal happiness.

My problem arises in linking from page to page. I could construct my series of steps as one .php file consisting of many "if/elseif" steps which would, after each form submission, allow the program to proceed to the next "elseif" statement, effectively looking like new pages.

However, I would prefer to have one "if" statement in each .php file which would send a form if some variable is empty. After the form is submitted, the variable would be filled and the program would go to one "elseif" statement. Inside of this elseif statement I would like for there to be a code that sends the user to a new .php page which would act as the next step in the path to euphoria. This would allow me to have a series of .php files that would each be individual pages in my site. Each would point to a new page at its end. Pretty basic I bet, but only if you know how.

Any help would be greatly appreciated.
User avatar
pickle
Briney Mod
Posts: 6445
Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:

Post by pickle »

So are you just wondering how to make a series of pages that forward to others? This basic format should work:

Code: Select all

<?PHP
if(isset($_POST['my_submit_button']))
{
  //process $_POST data
  header("Location: the_next_page.php");
}
else
{
  //output the form
}
?>
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
webjoe
Forum Newbie
Posts: 5
Joined: Wed Jun 01, 2005 12:50 am

Post by webjoe »

Just to add...

If you are trying to carry the values of your variables over, you can store the data into a Session, append them in your url (not recommended), or use hidden values.
bwv2
Forum Commoner
Posts: 83
Joined: Fri Jun 10, 2005 11:50 am
Location: AZ

how do I save to a session?

Post by bwv2 »

I would like to save my variables to a session, as mentioned in the above reply. Can someone tell me how to do that? Thanks, this is proving to be very helpful. 8O
hongco
Forum Contributor
Posts: 186
Joined: Sun Feb 20, 2005 2:49 pm

Post by hongco »

here is the example of using session
http://us2.php.net/function.session-start
Post Reply