473,382 Members | 1,404 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

How to retrieve checkbox array values?

Apologies if this is a stupid question ... I'm new to this PHP world!

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
  1. <table cellpadding="2px" cellspacing="1px" bgcolor="#FFFFDD"" width="600px" class="tableBorder" align="center">
  2.     <tr>
  3.         <td colspan="2" bgcolor="#FFCC66">&nbsp;</td>
  4.     </tr>   
  5.     <tr>
  6.         <td colspan="2" class="label">&nbsp;</td>
  7.     </tr>
  8.     <tr>
  9.         <td class="label" align="left" width="500"><?php echo $rquesttext; ?></td>
  10.     </tr>
  11.     <tr>
  12.         <td class="normalTextgrey" align="left"><?php echo $rquestdesc; ?></td>
  13.     </tr>
  14.     <?php foreach ($answers as $answer): ?>
  15.         <form action="?editquestion" method="post">
  16.         <tr class="smallTextBlack">
  17.             <p><input type="hidden" name="rparentid" value="<?php echo $answer['apid']; ?>"/></p
  18.             <p><input type="hidden" name="rsubid" value="<?php echo $answer['asid']; ?>"/></p>
  19.             <td align="left" valign=top>
  20.                 <input type="checkbox" name="chitems[]" value="<?php echo htmlspecialchars($answer['atext'], ENT_QUOTES,'UTF-8'); ?>">
  21.                 <?php echo htmlspecialchars($answer['atext'], ENT_QUOTES,'UTF-8'); ?>
  22.             </td>
  23.         </tr>
  24.         </form>
  25.     <?php endforeach; ?> <br />
  26.     <tr>
  27.         <td align="center"><input type="submit" value="Submit" name="submit1" /></td>
  28.     </tr>                   
  29.     <tr>
  30.         <td colspan="2" class="label">&nbsp;</td>
  31.     </tr>                   
  32. </table>
  33.  
And here is my php code:

Expand|Select|Wrap|Line Numbers
  1. if (isset($_POST['submit1']))
  2. {
  3. $box=$_POST['chitems'];
  4. while (list ($key,$val) = @each ($box)) { 
  5. echo "$val,"; 
  6.     exit();
  7. }
  8.  
Feb 10 '11 #1
1 2585
HaLo2FrEeEk
404 256MB
You're printing a new form for each checkbox, they need to all be in the same form. That means this line:

<form action="?editquestion" method="post">

Needs to go before the foreach, and his line:

</form>

Needs to go after the endforeach.
Feb 10 '11 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Nick | last post by:
Hi, I believe a dataset keeps a record of the original values of all rows before AcceptChanges() is called. Then how can I retrieve the original values? What function call do I use? Thanks!
2
by: MyndPhlyp | last post by:
For IE, I can retrieve an array of tags using: document.all.tags("tagname") For NS6 & 7 I can use: document.getElementsByTagName("tagname") Is there an equivalent for that ancient NS...
10
by: Geoff Cox | last post by:
Hello, I have a series of pages each of which creates an array of values. How do I keep all the array values until the last page? Cheers Geoff
4
by: Paul Morrison | last post by:
Hi, I have a checkbox array containing the id of a record in a MySQL database. The checkboxes are created dynamically depending on what is stored in the database. I want to send the checkbox...
1
by: artistlikeu | last post by:
i have a column which contains arrays of variable length. for example one array contains 5 elements, another contains 2 elements, another array 10 elements. i have 500 records in this column i...
0
by: Nolanclark | last post by:
Hi there. I've read a previous thread regarding the Old VB 6 checkbox array and how it's not really needed any more. That's fine, but I'm not really sure how to implement the checkbox control array...
3
realin
by: realin | last post by:
Hiya all, i am in deep trouble, i thought it was an easy task, but now its getting on my nerves. Well i have a div on a form, which contains a number of checkboxes, as <div...
5
by: Geethu03 | last post by:
Hi i have a array values in hidden format <form name="form2" method="post" action="test.php"> <input type="hidden" name="date_val" value="<%= date %>"> <input type="hidden" name="name_val"...
1
by: Suraj r | last post by:
Hi, I want to retrieve all the values of tag attr3 in the below xml.Can anybody please help me out on this?Thanks in advance!! <?xml version="1.0" encoding="ISO-8859-15" ?> <Roottag> ...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.