smk17 Posted October 17, 2012 Share Posted October 17, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/ Share on other sites More sharing options...
Jessica Posted October 17, 2012 Share Posted October 17, 2012 Yes, sessions. Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1385823 Share on other sites More sharing options...
JohnTipperton Posted October 18, 2012 Share Posted October 18, 2012 (edited) 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 October 18, 2012 by JohnTipperton Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1385957 Share on other sites More sharing options...
Jessica Posted October 18, 2012 Share Posted October 18, 2012 You don't NEED to use post. You could use GET even. but Sessions is what you SHOULD use. Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1385967 Share on other sites More sharing options...
White_Lily Posted October 18, 2012 Share Posted October 18, 2012 Sessions are better since they can be carried across the entire website, where as post can only be carried to the next page. Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1385969 Share on other sites More sharing options...
JohnTipperton Posted October 18, 2012 Share Posted October 18, 2012 (edited) 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 October 18, 2012 by JohnTipperton Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1386020 Share on other sites More sharing options...
shlumph Posted October 18, 2012 Share Posted October 18, 2012 Don't forget to clear the $_SESSION variable(s) out after you're done needing them. Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1386024 Share on other sites More sharing options...
White_Lily Posted October 18, 2012 Share Posted October 18, 2012 To clear the sessions when they are no longer needed just use; unset($session variables); Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1386027 Share on other sites More sharing options...
JohnTipperton Posted October 18, 2012 Share Posted October 18, 2012 To clear the sessions when they are no longer needed just use; unset($session variables); +1 yes correct. Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1386028 Share on other sites More sharing options...
smk17 Posted October 18, 2012 Author Share Posted October 18, 2012 This is excellent, thanks for the direction. Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1386030 Share on other sites More sharing options...
JohnTipperton Posted October 18, 2012 Share Posted October 18, 2012 This is excellent, thanks for the direction. good so it works now? Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1386039 Share on other sites More sharing options...
smk17 Posted October 18, 2012 Author Share Posted October 18, 2012 To John, lol, I wish I was that fast. I haven't even tried it yet. Just saying thanks for letting me know how to begin. Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1386076 Share on other sites More sharing options...
JohnTipperton Posted October 19, 2012 Share Posted October 19, 2012 To John, lol, I wish I was that fast. I haven't even tried it yet. Just saying thanks for letting me know how to begin. lol soon you will be that fast. hope you can make it. Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1386236 Share on other sites More sharing options...
smk17 Posted November 7, 2012 Author Share Posted November 7, 2012 (edited) 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 November 7, 2012 by smk17 Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1390904 Share on other sites More sharing options...
Jessica Posted November 7, 2012 Share Posted November 7, 2012 Make the name of the checkboxes an array. name="fish[]". On the next page, you can see what they chose in $_POST['fish']; Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1390906 Share on other sites More sharing options...
smk17 Posted November 7, 2012 Author Share Posted November 7, 2012 (edited) 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 November 7, 2012 by smk17 Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1390914 Share on other sites More sharing options...
smk17 Posted November 7, 2012 Author Share Posted November 7, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1390919 Share on other sites More sharing options...
Jessica Posted November 7, 2012 Share Posted November 7, 2012 Do you know what an array is? Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1390922 Share on other sites More sharing options...
smk17 Posted November 8, 2012 Author Share Posted November 8, 2012 Something that stores more than one value in a single variable? Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1390972 Share on other sites More sharing options...
Jessica Posted November 8, 2012 Share Posted November 8, 2012 Do you know how to work with them? If the answer is no, go read the manual. Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1390974 Share on other sites More sharing options...
trq Posted November 8, 2012 Share Posted November 8, 2012 You can't just simply echo an array because (as you stated) it contains more than a single value. You'll either need to loop through its contents, or (simpler), use implode to turn your array into a string so that you can echo it simply. Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1390977 Share on other sites More sharing options...
smk17 Posted November 8, 2012 Author Share Posted November 8, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/269592-carry-data-to-next-page-advice-needed/#findComment-1391114 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.