Jump to content

Carry Data To Next Page, Advice Needed


smk17

Recommended Posts

I've been given a job in creating sort of a flow diagram for employees in the seafood industry. This is what the client wants:

 

The user goes to a certain web page. On this first page they select from a list, (radio buttons probably) the fish that they receive or work on. Hit submit or next...

 

The next page displays the fish that they selected. Now they have to determine how they received the different species of fish (was it frozen, iced, or refrigerated, etc) Hit SUBMIT.

 

Now they are taken to one of three places, the Frozen page, the iced page, or the refrigerated page and have to answer more questions about potential food safety hazards depending on how they received the fish.

 

And on and on. The end result on the last page is an actual Hazard Analysis Worksheet, a six column table, that will be filled out appropriately with the answers and info they have given on the previous pages, they can then print this worksheet out as their own customized worksheet to bring to work.

 

So how do I approach this? PHP Sessions? How do I carry the selected data from page to page and then have that data be filled in to its appropriate column and row in the final table? Each user will end up with totally different results.

 

I'll admit I'm fairly new to php but can work my way through things if I know how to approach it and am very eager to learn how to do it. Thanks for any help

Link to comment
Share on other sites

you need to use POST.

 

index.php

 

<form name="test" action="view.php" id="test" method="post">
<input type="radio" name="Cake" id="Cake" value="Cake"/>
<input type="radio" name="Bread" id="Bread" value="Bread"/>
<input type="submit" value="Order" />
</form>

 

view.php

 

<?php
$Bread=$_POST['Bread'];
$Cake=$_POst['Cake'];
echo 'You Select '.$Bread.'</br>';
echo 'You Select '.$Cake.'<br>';
?>

Edited by JohnTipperton
Link to comment
Share on other sites

You don't NEED to use post. You could use GET even. but Sessions is what you SHOULD use.

 

he should be using the session when he is in the second part to store the variable since he is trying to create a 2 way submission.

 

Edited Code

 

you need to use POST or GET .

 

index.php

 

<form name="test" action="view.php" id="test" method="post">
<input type="radio" name="Whale" id="Whale" value="Whale"/>
<input type="radio" name="Shark" id="Shark" value="Shark"/>
<input type="submit" value="Order" />
</form>

 

view.php

 

<?php
$Whale=$_POST['Whale'];
$Shark=$_POST['Shark'];
$_SESSION['Whale']=$Whale;
$_SESSION['Shark']=$Shark;
echo 'You Select '.$Whale.'</br>';
echo 'You Select '.$Shark.'<br>';
?>
<form name="test" action="view2.php" id="test" method="post">
<input type="radio" name="Frozen" id="Frozen" value="Frozen"/>
<input type="radio" name="Iced" id="Iced" value="Iced"/>
<input type="submit" value="Order" />
</form>

 

 

view2.php

 

<?php
$Iced=$_POST['Iced'];
$Frozen=$_POST['Frozen'];
$Whale=$_SESSION['Whale'];
$Shark=$_SESSION['Shark'];
echo 'You Select '.$Whale.'</br> it has been'.$Iced;
echo 'You Select '.$Shark.'<br> it has been'.$Frozen;
?>

 

this is just a sample you will do the algorithm.. you may use POST or GET.

Edited by JohnTipperton
Link to comment
Share on other sites

  • 3 weeks later...

Okay, it's been a while, but finally had some time to test this. I have been able to figure out how to gather data from, let's say three pages of forms, and then on the last page, display the results where I see fit, which is exactly what I need. I am using php sessions. But the tutorial I used to do this only used one checkbox as an example.

 

My very first form asks the user to select which fish they work with. There are 24 different types of fish that they can choose from and they may work with all of them, or only some, I put them all as checkboxes.

 

Example:

<input type="checkbox" name="EscolarOilfish" id="EscolarOilfish" value="EscolarOilfish"/>Escolar or Oilfish<br />

<input type="checkbox" name="Gemfish" id="Gemfish" value="Gemfish"/>Gemfish<br />

<input type="checkbox" name="Herring" id="Herring" value="Herring"/>Herring<br />

 

so on and so on....

 

 

The fish that they select I want carried to the next page sort of like "Here are the fish you selected."

 

I have no idea how to do that, thanks for any help

 

I will also need the option of letting them go back to the first form if the results page indicates they checked some wrong boxes.

Steve

Edited by smk17
Link to comment
Share on other sites

Thanks Jessica,

 

Is this correct?

 

FORM page 1:

 

 

<input type="checkbox" name="fish[]" id="EscolarOilfish" value="EscolarOilfish"/>Escolar or Oilfish<br />

<input type="checkbox" name="fish[]" id="Gemfish" value="Gemfish"/>Gemfish<br />

<input type="checkbox" name="fish[]" id="Herring" value="Herring"/>Herring<br />

 

Page 2:

 

$_SESSION['fish'] = $_POST['fish'];

 

and then to print on page:

<?php echo $_SESSION['fish'] ?>

 

Just tried this and my output was the word "Array". not the selected fish

Edited by smk17
Link to comment
Share on other sites

Okay, I messed around a bit and got it to print out the selected fish,

 

$fish_array=$_POST['fish'];

$_SESSION['fish']=$fish_array;

 

<?php print_r ($fish_array) ?>

 

but it looks like this:

 

Array ( [0] => Bonito [1] => EscolarOilfish [2] => Kahawai [3] => Mackerel [4] => Mahi-Mahi [5] => Spearfish )

 

I need it to look like this:

Bonito, EscolarOilfish, Kahawai, Mackerel, Mahi-Mahi, Spearfish

 

I really have no idea what I'm doing, lol

Link to comment
Share on other sites

Thanks everyone for your help and direction, I've learned a lot (still MUCH more to learn) I wanted to show you what I've come up with so far:

 

http://dyson.cornell.edu/steve/session/test/index.php

 

Only the first CLICK HERE is functional on page 02.php. Remember, this is a newbie with a capital N. And the site is just a test site, it's not designed to look pretty yet.

 

I do know that I have nothing in place for error messages if someone tries to move ahead without selecting anything or forgets to check things.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.