I have created checkbox filed in my form.
The form is as below:
<html>
<head>
</head>
<body>
<div id="myform">
<form method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="id">
<div>Addressed by the Technology?</div>
<div>
<input type="checkbox" name="health[]" value="Workplace safety" style="margin-top:50px;">Workplace Safety<br>
<input type="checkbox" name="health[]" value=" Air pollution" style="margin-top:10px;">Air Pollution<br>
<input type="checkbox" name="health[]" value=" VOC reduction" style="margin-top:10px;">VOC Reduction <br>
<input type="checkbox" name="health[]" value=" Water pollution" style="margin-top:10px;">Water Pollution<br>
<input type="checkbox" name="health[]" value=" Soil pollution" style="margin-top:10px;">Soil Pollution<br>
<input type="checkbox" name="health[]" value=" Hazardous waste generation" style="margin-top:10px;">Hazardous Waste Generation<br>
<input type="checkbox" name="health[]" value=" Solvent emission" style="margin-top:10px;">Solvent Emission<br>
</div>
<input type="submit" name="submit" value="Submit" >
</form>
</div>
</div>
</body>
</html>
It is working fine submitting online, and view it everything working fine.
But if i edit the same form in php page the checkboxs showing unchecked every time:
php code is:
<?php ob_start(); ?>
<?php session_start(); if (empty($_SESSION['id'])) { header("Location:login.php"); } ?>
<?php include "conn.php";?>
<html>
<head><script src="jquery-3.2.1.min.js" type="text/javascript"></script></head>
<?php
if(isset($_POST['submit']))
{
$health = isset($_POST['health']) ? $_POST['health'] : '';
$check_msg = is_array($health) ? implode(", ", $health) : '';
$id=$_POST['id'];
$query=mysqli_query($con,"update job set health='".$check_msg."' where id=$id");
header("location:thank.php");
}
?>
<?php
$id=$_GET['id'];
$query=mysqli_query($con,"select * from job where id=$id")or die("Error: " . mysqli_error($con));
while($row=mysqli_fetch_array($query)){
}
?>
<body>
<form method="post" action="" enctype="multipart/form-data">
<input type="hidden" name="id" value="<?php echo $_GET['id'];?>">
<div>Addressed by the Technology?</div>
<input type="checkbox" name="health[]" value="Workplace safety" value="<?php echo $health;?>">Workplace Safety<br>
<input type="checkbox" name="health[]" value=" Air pollution" value="<?php echo $health;?>">Air Pollution<br>
<input type="checkbox" name="health[]" value=" VOC reduction" value="<?php echo $health;?>" >VOC Reduction<br>
<input type="checkbox" name="health[]" value=" Water pollution" value="<?php echo $health;?>" >Water Pollution<br>
<input type="checkbox" name="health[]" value=" Soil pollution" value="<?php echo $health;?>">Soil Pollution<br>
<input type="checkbox" name="health[]" value=" Hazardous waste generation" value="<?php echo $health;?>">Hazardous Waste Generation<br>
<input type="checkbox" name="health[]" value=" Solvent emission" value="<?php echo $health;?>" >Solvent Emission<br>
</div>
<input type="submit" name="submit" value="Submit">
</form>
</div>
</div>
</body>
</html>
Please help me to keep it remains checked if checkbox selected already at the time of editing the page
Thanks in advance Regards Elango
Aucun commentaire:
Enregistrer un commentaire