Judul : how to display multiple checkbox value from database in php
link : how to display multiple checkbox value from database in php
how to display multiple checkbox value from database in php
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.
}
}
?>
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.
}
}
?>
Demikianlah Artikel how to display multiple checkbox value from database in php
Sekianlah artikel how to display multiple checkbox value from database in php kali ini, mudah-mudahan bisa memberi manfaat untuk anda semua. baiklah, sampai jumpa di postingan artikel lainnya.
Anda sekarang membaca artikel how to display multiple checkbox value from database in php dengan alamat link https://othereffect.blogspot.com/2018/05/how-to-display-multiple-checkbox-value.html
0 Response to "how to display multiple checkbox value from database in php"
Post a Comment