how to get checkbox value in php if checked?

Today, We want to share with you how to get checkbox value in php if checked.In this post we will show you how to get checked and unchecked checkbox value in php, hear for The checkbox element in HTML allows us to select multiple items from the group of values. we will give you demo and example for implement.In this post, we will learn about Get multiple checkbox value using jquery PHP with an example.

Get checked Checkboxes value with PHP

Laravel get multiple checkbox value From View to Controller
Laravel get multiple checkbox value From View to Controller

1. Read $_POST checked values

Select players
PHP
JavaScript
jQuery
Angular JS

PHP

if(isset($_POST['submit'])){

    if(!empty($_POST['player_name'])) {    
        foreach($_POST['player_name'] as $value){
            echo "value : ".$value.'
'; } } }

Completed Code

Select players
Parthiv
Jasmit
Jadeja
Ajankye
'; } } } ?>

3. Table structure

CREATE TABLE `players` (
  `id` int(11) NOT NULL PRIMARY KEY AUTO_INCREMENT,
  `player` varchar(80) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

Configuration

config.php


Insert and Display checked values from Database

Completed Code




  

  
  
  
  
Select players
0){ $result = mysqli_fetch_assoc($fetchLang); $checked_arr = explode(",",$result['player']); } // Create checkboxes $players_arr = array("Parthiv","Jasmit","Jadeja","Ajankye"); foreach($players_arr as $player){ $checked = ""; if(in_array($player,$checked_arr)){ $checked = "checked"; } echo ' '.$player.'
'; } ?>

I hope you get an idea about if checkbox is checked value=1 else 0 in php.
I would like to have feedback on my infinityknow.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Leave a Comment