karlokokkak

Untitled

Mar 28th, 2018
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.29 KB | None | 0 0
  1. <?php
  2. $link = mysqli_connect("localhost", "root", "himura", "mels");
  3.  
  4. // Check connection
  5. if($link === false){
  6.     die("ERROR: Could not connect. " . mysqli_connect_error());
  7. }
  8. ?>
  9.  
  10. <form action="" method="post">
  11. <input type="checkbox" name="check_list[]" value="C/C++" <?php echo ( isset($_POST['check_list']) AND in_array( "C/C++", $_POST['check_list'] ) ) ? "checked" : ""; ?>><label>C/C++</label><br/>
  12. <input type="checkbox" name="check_list[]" value="Java" <?php echo ( isset($_POST['check_list']) AND in_array( "Java", $_POST['check_list'] ) ) ? "checked" : ""; ?>><label>Java</label><br/>
  13. <input type="checkbox" name="check_list[]" value="PHP" <?php echo ( isset($_POST['check_list']) AND in_array( "PHP", $_POST['check_list'] ) ) ? "checked" : ""; ?>><label>PHP</label>  <br/>
  14. <input type="submit" name="submit" value="Submit"/>
  15.  
  16. </form>
  17.  
  18. <?php
  19.  
  20. if(isset($_POST['submit']))
  21. {//to run PHP script on submit
  22.     if(!empty($_POST['check_list'])) {
  23.         foreach($_POST['check_list'] as $selected) {
  24.             if($selected!="") {
  25.                 $stmt = $link->prepare('INSERT INTO `checkbox` (`php_value`) VALUES (?)');
  26.                 $stmt->bind_param('s', $selected);
  27.                 $stmt->execute();
  28.                 $stmt->close();
  29.             }
  30.         }
  31.         mysqli_close($link);
  32.     }
  33. }
  34.  
  35.  
  36. ?>
Advertisement
Add Comment
Please, Sign In to add comment