Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $link = mysqli_connect("localhost", "root", "himura", "mels");
- // Check connection
- if($link === false){
- die("ERROR: Could not connect. " . mysqli_connect_error());
- }
- ?>
- <form action="" method="post">
- <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/>
- <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/>
- <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/>
- <input type="submit" name="submit" value="Submit"/>
- </form>
- <?php
- if(isset($_POST['submit']))
- {//to run PHP script on submit
- if(!empty($_POST['check_list'])) {
- foreach($_POST['check_list'] as $selected) {
- if($selected!="") {
- $stmt = $link->prepare('INSERT INTO `checkbox` (`php_value`) VALUES (?)');
- $stmt->bind_param('s', $selected);
- $stmt->execute();
- $stmt->close();
- }
- }
- mysqli_close($link);
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment