mpsn Posted November 19, 2011 Share Posted November 19, 2011 Hi, I am building a learning site for kids. On this page, 1)there's a textbox to choose the directory to save the list of new words they learnt 2)an HTML table that displays all the words they have stored to db (they choose the words to store to directory via checkboxes next to each word in this HTML table) 3)then they click submit and it stores these new words they can use to file in their specified directory. My quesiton is should I use $_GET or $_POST? (somehow I think I need to output the primary key in step 2) for query string, so maybe I should also store directory that user types in textbox as query string too? Any help much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/251416-get-or-post-help/ Share on other sites More sharing options...
voip03 Posted November 19, 2011 Share Posted November 19, 2011 The POST Method BEST for you. ref:http://www.tutorialspoint.com/php/php_get_post.htm Quote Link to comment https://forums.phpfreaks.com/topic/251416-get-or-post-help/#findComment-1289490 Share on other sites More sharing options...
mpsn Posted November 19, 2011 Author Share Posted November 19, 2011 How do I keep track of the checked checkboxes (I know I have to: <input type="checkbox" name="items[]" /> BUT if I use $_POST, how do I refer to each checked item? Any help much appreciated! Quote Link to comment https://forums.phpfreaks.com/topic/251416-get-or-post-help/#findComment-1289491 Share on other sites More sharing options...
voip03 Posted November 19, 2011 Share Posted November 19, 2011 <form action="test.php" method="post"> <input type="checkbox" name="apple" value="apple">apple <br> <input type="checkbox" name="orange" value="orange">orange <br> <input type="submit"> </form> <? foreach ($_POST as $key => $value ) echo "<br>$key is checked"; ?> Hope you can get the idea Quote Link to comment https://forums.phpfreaks.com/topic/251416-get-or-post-help/#findComment-1289498 Share on other sites More sharing options...
Pikachu2000 Posted November 19, 2011 Share Posted November 19, 2011 That's actually not such a great idea. A group of related checkboxes should be configured as an array in the form so you can then loop only through that group to get the values. <input type="checkbox" name="choices[]" value="apple">apple<br> <input type="checkbox" name="choices[]" value="orange">orange<br> <input type="checkbox" name="choices[]" value="banana">banana<br> <input type="checkbox" name="choices[]" value="grapes">grapes<br> The values of the checked boxes will be available in array form in $_POST['choices'] Quote Link to comment https://forums.phpfreaks.com/topic/251416-get-or-post-help/#findComment-1289528 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.