i want to know the value of the checkbox which are checked and put theses values to cookie which is like a shopping card.
my problem is how can i know which checkbox are checked or not by php (it works fine in javascript).
plz
handling multicheckbox with php
Moderator: General Moderators
in html
in php
I hope I understood your question right.
Code: Select all
<input type="checkbox" name="storage[id1_or_something_to_distinguish_them_with]" value="Y">
<input type="checkbox" name="storage[id2_or_something_to_distinguish_them_with]" value="Y">
........Code: Select all
$checked_checkboxes = $_POST['storage']; // array with only checked checkboxes will be stored in here.it does work but it doesn't display the value of checkbox
plz tell me the way
regard,
Code: Select all
<?php
if (isset($_REQUEST["action"]) && $_REQUEST["action"]='submitted')
{
$mycheck = $_POST['chk'];
foreach ($mycheck as $selectedcar)
{
if (isset($mycheck))
{
echo "$mycheck<br>";
}
}
}
?>regard,
jmut wrote:in htmlin phpCode: Select all
<input type="checkbox" name="storage[id1_or_something_to_distinguish_them_with]" value="Y"> <input type="checkbox" name="storage[id2_or_something_to_distinguish_them_with]" value="Y"> ........
I hope I understood your question right.Code: Select all
$checked_checkboxes = $_POST['storage']; // array with only checked checkboxes will be stored in here.
jaylin wrote:it does work but it doesn't display the value of checkboxplz tell me the wayCode: Select all
<?php if (isset($_REQUEST["action"]) && $_REQUEST["action"]='submitted') { $mycheck = $_POST['chk']; foreach ($mycheck as $selectedcar) { if (isset($mycheck)) { echo "$mycheck<br>"; } } } ?>
regard,
Your foreach is wrong... you never used $selectedcar
just dump
var_dump($myckeck); // and see if the array have the content you expect.
probably should be ok ittarating with
Code: Select all
foreach ($mycheck as $id => $checkbox_value) {
//you don't need isset.........because it is only the checked boxes
echo $checkbox_values['id1_or_something_to_distinguish_them_with'];
}