Jump to content

Recommended Posts

How can I use php to get the check boxs values (only the checked one):

 

if you are posting it using a PHP form something in this manner

($_POST['checkboxname] == "ON")

 

or a group of checkboxes

 

page_html.php

 

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

      <input type="checkbox" id="colour[]" value="red"> Cat<br>

      <input type="checkbox" id="colour[]" value="blue"> Mouse<br>

      <input type="checkbox" id="colour[]" value="green"> Car<br>

      <input type="checkbox" id="colour[]" value="yellow"> DaniWeb

      </form>

 

php.php

 

      <?php

      $things = serialize($_POST['colour']);

 

      $query = "INSERT INTO table(colour) values($colour)";

      mysql_query($query) or die(mysql_error());

      ?>

 

Just turn it into an array and dump the contents to db. You have to "serialize" the data first and don't forget to "unserialize" when you are taking the data back out.

Link to comment
https://forums.phpfreaks.com/topic/206856-get-check-box-value/#findComment-1081775
Share on other sites

Dear all,

 

How can I use php to get the check boxs values (only the checked one):

 

<input type="checkbox" name="option[]" value="Milk"> Milk<br>

<input type="checkbox" name="option[]" value="Butter"> Butter<br>

<input type="checkbox" name="option[]" value="Cheese"> Cheese

 

Thanks!!

 

Hi,

 

if (isset($_POST['option']) && is_array($_POST['option']))
{
foreach ($_POST['option'] as $option)
{
	echo $option.', ';
}
}

Link to comment
https://forums.phpfreaks.com/topic/206856-get-check-box-value/#findComment-1081788
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.