PHP 8 Checkbox Value Store In Database Example




PHP 8 Checkbox Value Store In Database Example

Hello Friends,

Now, let's see example of PHP 8 Checkbox Value Store In Database Example. I explained simply about PHP 8 Checkbox Set to Check Based on Database Value Example. I would like to show you Get checked Checkboxes value with PHP 8 MySQL. we will help you to give example of PHP Checkbox Checked from Database Example.

I will give you simple example of PHP 8 - Checkbox Checked With Database Value .

So, let's see bellow solution:


<!doctype html>

<html lang="en">


<!-- Bootstrap CSS -->

<title>PHP 8 Checkbox Value Store In Database Example</title>

<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 8 Checkbox Value Store In Database Example -</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...

#PHP 8