Monday, 14 May 2018

how to display multiple checkbox value from database in php

01:49

Step 1:  

SQL>
create table  userrecord (
id int primary key ,
name   varchar(200)
);


Step 2: write code for checkbox.php file:

<?php
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ankit";


// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn)
{
    die("Connection failed: " . mysqli_connect_error());
}

$sql="select * from userrecord";

$result=mysqli_query($conn,$sql);
while ($row=mysqli_fetch_array($result))
{

echo '<form action="select.php" method="post">

<input type="checkbox" name="check_list[]" value="'.$row['id'].'"><label> "'.$row['name'].'"</label><br/>';



}
echo '<input type="submit" name="submit" value="Submit"/>
</form>';

?>


Step 3: write code for   select.php  file:

<?php

$servername = "localhost";
$username = "root";
$password = "";
$dbname = "ankit";


// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

if(isset($_POST['submit'])){//to run PHP script on submit


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




$data=implode(',',$_POST['check_list']);

echo $sql="select  *  from  userrecord  where  id  IN($data)";

$result=mysqli_query($conn,$sql);

while($row=mysqli_fetch_array($result))
{
echo "id=".$row['id'];
echo "name=".$row['name'];

}



// Loop to store and display values of individual checked checkbox.

}


}
?>

Written by

We are Creative Blogger Theme Wavers which provides user friendly, effective and easy to use themes. Each support has free and providing HD support screen casting.

4 comments:

  1. Thanks For Sharing. It IS very helpful For Everyone ....
    If You Are Looking Best PHP training in chandigarh click here

    ReplyDelete
  2. Having trouble in Hire Php Web Developer who is reliable and experienced enough to implement the functionality and design you need? Reach out to us we have a team of developers, designers and seo experts that fulfill your dreams. we provide you Custom PHP Software Development USA, PHP Application Development India, Custom Php Software Solutions UK. Our services will be on budget of clients. We provide 100% quality assurance and dedicated to meet deadlines of the project.

    ReplyDelete

PHP Training Mumbai, PHP MySQL Training Mumbai, PHP Course Mumbai, PHP Institute Mumbai

 

© 2013 PHP TRAINING IN MUMBAI BY OM SIR . All rights resevered. Designed by OM SIR

Back To Top