mercredi 25 juillet 2018

Save once checkbox value inside a checkbox loop

I have this code:

<?php
if(isset($_POST['submit'])) {
 if(isset($_POST['sharks'])) {
      $_SESSION['value'] = $_POST['sharks'];
  } else {
      $_SESSION['value'] = '';
  }
}
?>
<form action="" method="POST">
  <?php
  echo '<input name="sharks" type="checkbox" value="1" id="sharks" ';
    if ($_SESSION['value'] == 1) {
      echo ' checked="checked"';
    }
  echo ">";
  ?>
  <br>
  <button type="submit" name="submit" value="Save">Salva</button>
</form>

I'm already inside a loop of users, I just want to add a checkbox next to them and save the value of that checkbox connected to that user.
enter image description here

When I try to save the checkbox this is what happen:
enter image description here

Thank you all




Aucun commentaire:

Enregistrer un commentaire