mercredi 26 août 2020

How can we get checkboxes which are checked

<?php 
session_start();
require  'conn.php';
global $conn;

if(isset($_POST['test'])){  
  foreach($_POST['test'] as $key => $val){
    mysqli_set_charset($conn,"utf8");    
     $sql = "SELECT * FROM Jautajumi_Prof where TEMA = ? ";
     $stmt = mysqli_stmt_init($conn); 

     if(!mysqli_stmt_prepare($stmt, $sql)){
      header ('location: test.php?error');
      exit();
    
      }else{
        mysqli_stmt_bind_param($stmt, "s", $val);
        mysqli_stmt_execute($stmt);
        $result = mysqli_stmt_get_result($stmt);
        
      }  
     
      while ($row = mysqli_fetch_assoc($result)){           
          echo "         
          <h4>".$row["JAUTAJUMS"]."</h4>
          <input type='checkbox' name='check_list[]' value='".$row["ATBILDE_A"]."' >            
          <label>".$row["ATBILDE_A"]."</label>
          <input type='checkbox' name='check_list[]' value='".$row["ATBILDE_B"]."'>            
          <label>".$row["ATBILDE_B"]."</label>
          <input type='checkbox' name='check_list[]' value='".$row["ATBILDE_C"]."'>            
          <label>".$row["ATBILDE_C"]."</label>
          <input type='checkbox' name='check_list[]' value='".$row["ATBILDE_D"]."'>           
          <label>".$row["ATBILDE_D"]."</label>              
          ";             
      } 
     
  }
}

?>
 <div class="delete">
        <form method="post" action="answer.inc.php">
            <input name="delete" type="submit" id="delete" value="DELETE">
        </form>
    </div>
<?php 



?>

I am trying to make a web page for students and my self where can i
To choose a topic what they like and they will see a question which needs to ba answered. In my code I get the answers from the SQL but I need them to store somewhere and I made like a second file where I want to trie to save or event get to screen but it won't show it just submits for me.

<?php 
if (empty($_POST['delete'])){
  foreach($_POST['check_list'] as $item){
    echo $item;
  }
}

?>



Aucun commentaire:

Enregistrer un commentaire