Delete a name entered in the form by selecting a checkbox

0

I am practicing the SESSION_START () in php.

In the following code I show you how to enter names in the form, a list is created below with the names entered, each name has a checkbox in front and what I can not do is that when I check the checkbox, that name is deleted from the list, either instantly or with a delete button.

    <?php
  SESSION_START();
 ?>

<!DOCTYPE html>
<html lang="en" dir="ltr">
  <head>
    <meta charset="utf-8">
    <title>Sesiones</title>
  </head>
  <body>
    <form action="index.php" method="post">
      <label>Nombre: </label><input type="text" name="nombre">
      <br><br>
      <input type="submit" name="submit" value="Enviar">
<br><br><br>
    </form>
  </body>
</html>


<?php

if (isset($_POST['nombre']) == "") {
  echo "No hay nombres de usuarios";
}

else{

    // Si existe y es un array ingresamos el nuevo nombre:
    if (isset($_SESSION['nombre']) ? is_array($_SESSION['nombre']) : false) {
        array_push($_SESSION['nombre'], $_POST['nombre']);
    }
    else {
    // si no es un array (o no existe), lo convertimos en array:
        $_SESSION['nombre'] = array($_POST['nombre']);
    }


    foreach($_SESSION['nombre'] as $nombre) {

        echo '<input type="checkbox" name="check">'.$nombre.'<br>';
    }

}


  echo "<br><br>";
  echo "<a href='cerrar.php'>Cerrar Sesión</a>";

?>

Thank you!

    
asked by davescode 09.11.2018 в 10:08
source

0 answers