Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Your problem is most likely related to the way html returns values of checkboxes. </p> <p>if a checkbox is checked-in it's value is returned, if it isn't checked-in no value whatsoever is returned.</p> <p>In a case you would be picking colours from checkboxes called <code>name='colours[]'</code> your values will be like this: (fist line is choices, second the returned array in php)</p> <pre><code>[x] red [ ] green [ ] blue [x] yellow [ ] black [ ] white array('red','yellow') [ ] red [ ] green [ ] blue [x] yellow [ ] black [x] white array('yellow','white') [ ] red [ ] green [ ] blue [ ] yellow [ ] black [ ] white null (no array returned) </code></pre> <p>one way of doing it is using different name for each option and check for your values in this style:</p> <pre><code>$red = isset($_POST['ck_red']); $green = isset($_POST['ck_green']); ... </code></pre> <p>That of course in case you defined your red check box as <code>name='ck_red'</code> etc.</p> <p><strong>EDIT</strong><br/>(Your code follows)</p> <p>html:</p> <pre><code>&lt;INPUT TYPE="CHECKBOX" NAME="areas[]" VALUE="1"&gt;The Homeless&lt;/INPUT&gt;&lt;BR /&gt; &lt;INPUT TYPE="CHECKBOX" NAME="areas[]" VALUE="2"&gt;The Elderly&lt;/INPUT&gt;&lt;BR /&gt; &lt;INPUT TYPE="CHECKBOX" NAME="areas[]" VALUE="3"&gt;Refugees&lt;/INPUT&gt;&lt;BR /&gt; &lt;INPUT TYPE="CHECKBOX" NAME="areas[]" VALUE="4"&gt;The handicapped&lt;/INPUT&gt;&lt;BR /&gt; </code></pre> <p>php:</p> <pre><code>$areas[] = "$_POST[areas]"; foreach ($areas as $value) { echo $value . " "; } </code></pre> <p><strong>Answer</strong>: You have an error is in the assignment <code>$areas[] = "$_POST[areas]";</code> and namely in using the <code>"</code> around the <code>$_POST[areas]</code> - by doing so you are telling the parser, that you want to know the textual value of variable $_POST[areas] which is an array and php's way of dealing with it is to return TEXT <strong>'array'</strong> instead of (as for example in javascript) the list of elements delimited by coma. The other error is, eventhough it would work as you have it, that you are reffering to undefined constant <code>areas</code> instead of to string literal <code>'areas'</code> as in <code>$_POST['areas']</code> (notice the single quotes <code>'</code> around the key name. The last mistake is assigning the <code>$_POST['areas']</code> to <code>$areas[]</code> instead of <code>$areas</code> (without the <code>[]</code>). What you are doing there is you are adding a new element of array to array (areas) to which you are assigning the value of <code>$_POST['areas']</code> so in case it was without the first error (the <code>"</code>) it would create two dimensional array <code>areas =&gt; array(array('a','b','c'))</code></p> <p>Fix (php):</p> <pre><code>$areas = $_POST['areas']; foreach ($areas as $value) { echo $value . " "; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload