dimanche 25 août 2019

How to update checkbox values into html?

I want to update my checkbox value .I have the update command successfully running .I can get the values but I am unable to check the appropriate checkboxes in the edit form.Plzz try to help me .Thanks in advance

<?php

.....

$id = isset($_GET['id']) ? $_GET['id'] : '';
$s = "SELECT * from newform WHERE id='$id'";
$result = mysqli_query($connect,$s);
$num = mysqli_num_rows($result);
if($num > 0){
    $row = $result->fetch_array();
    $yr_revision = $row['yr_revision'];
    $b = explode(",",$yr_revision);

.....

?>


 4.2 Mention the  years ?
....
    <input type="checkbox" name="yr_revision[]" value="13-14" 
    <?php echo (in_array("13-14",$b)) ? 'checked' : '' ; ?>>
    2013-2014
    <input type="checkbox" name="yr_revision[]" value="14-15"
    <?php echo (in_array("14-15",$b)) ? 'checked' : '' ; ?>>
    2014-2015

I tried using terminal statements 

.......
    <input type="checkbox" name="yr_revision[]" value="15-16"
    <?php if(in_array("15-16",$b)){echo "checked";}?>>
    2015-2016
    <input type="checkbox" name="yr_revision[]" value="16-17"
    <?php if(in_array("15-16",$b)){echo "checked";}?>>
    2016-2017

......

`````


And I tried using if statements but nothing actually worked

Only the 1st checkbox gets checked each and everytime  others don't
But when I print the $b values as string it displays all checked values

How to update them in html using php?




Aucun commentaire:

Enregistrer un commentaire