I have got an html form that has checkboxes dynamically created from MySQL. I use an array to create the list of checkboxes. A user will then check the box as appropriate and I want to store the values. However, only the 1st checkbox value in the array is being retrieved when I hit the submit button.
Would really appreciate an guidance. Thanks
Here is my html code snippet:
Expand|Select|Wrap|Line Numbers
- <table cellpadding="2px" cellspacing="1px" bgcolor="#FFFFDD"" width="600px" class="tableBorder" align="center">
- <tr>
- <td colspan="2" bgcolor="#FFCC66"> </td>
- </tr>
- <tr>
- <td colspan="2" class="label"> </td>
- </tr>
- <tr>
- <td class="label" align="left" width="500"><?php echo $rquesttext; ?></td>
- </tr>
- <tr>
- <td class="normalTextgrey" align="left"><?php echo $rquestdesc; ?></td>
- </tr>
- <?php foreach ($answers as $answer): ?>
- <form action="?editquestion" method="post">
- <tr class="smallTextBlack">
- <p><input type="hidden" name="rparentid" value="<?php echo $answer['apid']; ?>"/></p
- <p><input type="hidden" name="rsubid" value="<?php echo $answer['asid']; ?>"/></p>
- <td align="left" valign=top>
- <input type="checkbox" name="chitems[]" value="<?php echo htmlspecialchars($answer['atext'], ENT_QUOTES,'UTF-8'); ?>">
- <?php echo htmlspecialchars($answer['atext'], ENT_QUOTES,'UTF-8'); ?>
- </td>
- </tr>
- </form>
- <?php endforeach; ?> <br />
- <tr>
- <td align="center"><input type="submit" value="Submit" name="submit1" /></td>
- </tr>
- <tr>
- <td colspan="2" class="label"> </td>
- </tr>
- </table>
Expand|Select|Wrap|Line Numbers
- if (isset($_POST['submit1']))
- {
- $box=$_POST['chitems'];
- while (list ($key,$val) = @each ($box)) {
- echo "$val,";
- }
- exit();
- }