Create dynamic CheckBox in PHP using MySQL database records

How to generate complete dynamic check box with all the values coming from MySQL db and set into checkbox.

In this tutorial we are creating a complete dynamic checkbox means the items of checkbox is directly coming through MySQL database tables records. So with the use of dynamic functionality website admin dose not have to add manually checkbox items each time after updating them. Just update you checkbox table and it will automatically update items of checkbox at front hand view. So here is the complete step by step tutorial for Create dynamic CheckBox in PHP using MySQL database records.

android-project-download-code-button

How to Create dynamic CheckBox in PHP using MySQL database records.

Code for dynamic-checkbox.php file.

 <!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Create dynamic CheckBox in PHP using MySQL database records</title>
</head>

<body>

<?php

include 'dbconfig.php';

$subjectName = "SELECT * FROM demo_table_8 value";

$subject = mysql_query( $subjectName, $conn );
?>
<h2> Dynamic CheckBox </h2>
 
 <form method="post" action=" ">
 
 <?php
 
 while($data = mysql_fetch_array($subject)) {
 
 echo "<input type='checkbox' value='{$data['value']}'>" . $data['value'] . '</br>';
}

?>
 
 </form>

</body>
</html>

Code for dbconfig.php file.

 <?php

//Define your host here.
$hostname = "localhost";

//Define your database username here.
$username = "root";

//Define your database password here.
$password = "";

//Define your database name here.
$dbname = "test";

 $conn = mysql_connect($hostname, $username, $password);
 
 if (!$conn)
 
 {
 
 die('Could not connect: ' . mysql_error());
 
 }
 
 mysql_select_db($dbname, $conn);



?>

Screenshots:

Create dynamic CheckBox in PHP using MySQL database records

Click here to download Create dynamic CheckBox in PHP using MySQL database records project with MySQL database file included.