PHP Checkbox Checked from Database Example

Mar 01, 2022 . Admin

Hello Friends,

I am going to explain you PHP checkbox checked from Database. You will learn check checkbox is checked or not in PHP Database example. In side this article we will see how to show checkbox check in database.

This article will give you simple example of how to checked checkbox from Database in PHP. We will use get search checkbox checked from PHP.

You can use from how to use checkbox check or not in PHP. I will give you simple PHP checkbox checked from Database.

So, let's see bellow solution:

<!doctype html>
<html lang="en">
    <!-- Bootstrap CSS -->
    <link href="" rel="stylesheet">

        $dbhost = 'localhost';
        $dbuser = 'root';
        $dbpass = '';
        $db = 'shope';

        $conn = mysqli_connect($dbhost, $dbuser, $dbpass , $db) or die($conn);  


            if(!empty($_POST['lang'])) {

                $lang = implode(",",$_POST['lang']);

                // Insert and Update record
                $checkEntries = mysqli_query($conn,"SELECT * FROM languages");
                if(mysqli_num_rows($checkEntries) == 0){
                    mysqli_query($conn,"INSERT INTO languages(language) VALUES('".$lang."')");
                    mysqli_query($conn,"UPDATE languages SET language='".$lang."' ");


    <div class="container mt-5">
        <div class="row">
            <div class="col-md-12">
                <div class="card w-75 m-auto">
                    <div class="card-header bg-info text-white text-center">
                        <h4>PHP Checkbox Checked from Database -</h4>
                    <div class="card-body">
                        <form method="post" action="">

                                $checked_arr = array();

                                // Fetch checked values
                                $fetchLang = mysqli_query($conn,"SELECT * FROM languages");
                                if(mysqli_num_rows($fetchLang) > 0){
                                  $result = mysqli_fetch_assoc($fetchLang);
                                  $checked_arr = explode(",",$result['language']);

                                // Create checkboxes
                                $languages_arr = array("PHP","JavaScript","jQuery","AngularJS");
                                foreach($languages_arr as $language){

                                    $checked = "";
                                        $checked = "checked";

                                    echo '<div class="form-check">
                                            <input type="checkbox" name="lang[]" class="form-check-input" style="width: 20px;height: 20px;left: 10px;top: -1px;" value="'.$language.'" '.$checked.' > '.$language.'
                                          </div><br> ';
                            <input type="submit" value="Submit" name="submit" class="btn btn-primary">

It will help you...