我尝试使用复选框方法编辑我的选择,检查以前在数据库中的值,而不检查其他值。我尝试做的是检查其他复选框或取消选中上一个选中的复选框,但是当我提交我的版本时,没有任何事情发生,因为它没有从复选框中获取值我不知道为什么。这是我的代码。谢谢
<?php
if(isset($_GET['Institute_Code']))
{
$Institute_Code=$_GET['Institute_Code'];
$getselect=mysqli_query($con,"SELECT radio FROM institute WHERE Institute_Code='$Institute_Code'");
while($row=mysqli_fetch_array($getselect))
{ $Degree_Programs = $row ['radio'];
}}
?>
<form action="#" method="post" name="add_Institute">
<div class="container">
<!--add here-->
<?php
$char="";
$name[]="";
$j=0;
$dbvalue="";
if($Degree_Programs!=NULL )
{
$Degree_ProgramStrlen=Strlen($Degree_Programs);
for ($i=0; $i<=$Degree_ProgramStrlen; $i++)
{
$char = substr( $Degree_Programs, $i, 1 );
if($char == ',')
{
//echo $name[$j];
//$name="";
$j=$j+1;
$name[$j]="";
}
else
{
$name[$j] .= $char;
}
}
}
else
{} ?>
<!--" >-->
<div class="row col-md-offset-1">
<div class="col-md-9 ">
<?php echo "<b>Degree Programs</b>"; ?>
<br>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='Matric Arts')
$dbvalue=$name[$i];
} ?>
<label>Matric Arts</label>
<input type="checkbox" name="check_DegreePrograms[]" value="Matric Arts" <?php
$value="Matric Arts";
echo ( $dbvalue==$value ? 'checked' : '');?>>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='Matric Science')
$dbvalue=$name[$i];
} ?>
<label for="tag_2">Matric Science</label>
<input type="checkbox" name="check_DegreePrograms[]" id="tag_2" value="Matric Science" <?php
$value="Matric Science";
echo ( $dbvalue==$value ? 'checked' : '');?>>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='FSc. Pre-Engineering')
$dbvalue=$name[$i];
} ?>
<label for="tag_3">FSc. Pre-Engineering</label>
<input type="checkbox" name="check_DegreePrograms[]" id="tag_3" value="FSc. Pre-Engineering" <?php
$value="FSc. Pre-Engineering";
echo ( $dbvalue==$value ? 'checked' : '');?>>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='Fsc. Pre-Medical')
$dbvalue=$name[$i];
} ?>
<label for="tag_4">FSc. Pre-Medical</label>
<input type="checkbox" name="check_DegreePrograms[]" id="tag_4" value="FSc. Pre-Medical"<?php
$value="FSc. Pre-Medical";
echo ( $dbvalue==$value ? 'checked' : '');?>>
<?php for($i=0;$i<count($name)-1;$i++)
{ if($name[$i]=='I.com')
$dbvalue=$name[$i];
} ?>
</div>
</div>
<input type="Submit" name="Submit" value="Submit" class="btn btn-success pull-right"/>
</form>
</div>
<?php //} }
$pets ="";
$flag =0;
if(isset($_GET['Institute_Code']))
{
$Institute_Code=$_GET['Institute_Code'];
if (isset($_POST['Submit'])) {
if(isset($_POST['submit'])){//to run PHP script on submit
if(!empty($_POST['check_DegreePrograms'])){
// Loop to store and display values of individual checked checkbox.
foreach($_POST['check_DegreePrograms'] as $selected){
$pets .= $selected . ",";
$flag = 1;
}
}
}
if ($flag == 1) {
$pets = rtrim($pets);
}
$updated = mysqli_query($con ,"UPDATE institute set radio='$pets' where Institute_Code=1233");
if($updated)
{
echo "Data successfully updated...";
}
else {
die('Could not update data: ' . mysql_error());
}
}
}
?>
<?php
include 'footer.php';
?>'