Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.09 KB | None | 0 0
  1.   try{
  2.   $db = new PDO('mysql:host=localhost;dbname=questionnaire', 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8'));
  3. }catch(Exception $e){
  4.   echo 'Erreur : '.$e->getMessage().'<br />';
  5.   echo 'NĀ° : '.$e->getCode();
  6. }
  7.  
  8. $question1 = $_POST['question1'];
  9.  
  10.  
  11. $query = $db->prepare("INSERT INTO form (question1 )
  12. VALUES ('".$question1."')");
  13.  
  14.    $question1 = isset($_POST['question1']) ? $_POST['question1'] : array();
  15. foreach($question1 as $reponse1) {
  16.     // here you can use $value
  17.     $query->bindValue('question1', $reponse1, PDO::PARAM_STR);
  18. }
  19.   $query->execute();
  20.  
  21.   <div class="col-md-6">
  22.       <label for="question1">
  23.         <input id="question1" type="checkbox" class="form-control" name="question1[]" value="A">
  24.         A
  25.       </label>
  26.       <label for="question1">
  27.         <input id="question1" type="checkbox" class="form-control" name="question1[]" value="B">
  28.         B
  29.       </label>
  30.       <label for="question1">
  31.         <input id="question1" type="checkbox" class="form-control" name="question1[]" value="C">
  32.         C
  33.       </label>
  34.     </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement