Jump to content

get or post help


mpsn

Recommended Posts

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!

Link to comment
Share on other sites

<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

Link to comment
Share on other sites

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']

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.