Advertisement
Guest User

Untitled

a guest
May 14th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. !-- Multiple Checkboxes -->
  2. <?php
  3. mysql_connect("localhost", "user", "pass") or die("Connection Failed");
  4. mysql_select_db("sound")or die("Connection Failed");
  5. ?>
  6. <div class="control-group">
  7. <?php
  8. $query = "SELECT * FROM video";
  9. $result = mysql_query($query);
  10. while ($line = mysql_fetch_array($result, MYSQL_ASSOC)) {
  11. ?>
  12. <div class="controls">
  13. <label class="checkbox">
  14. <input type="checkbox" name="videoid" value="<?php echo $line[id]?>"><?php echo $line[title]?>
  15. </label>
  16. </div>
  17. <?php } ?>
  18.  
  19. <!-- Button -->
  20. <div class="control-group">
  21. <label class="control-label" for="submit_select"></label>
  22. <div class="controls">
  23. <button id="submit" name="sub" class="btn btn-primary">Submit</button>
  24. </div>
  25. </div>
  26.  
  27. </fieldset>
  28. </form>
  29.  
  30. <?php
  31. if(isset($_POST['sub']))
  32. {
  33. $host="localhost";//host name
  34. $username="user"; //database username
  35. $password="pass";//database word
  36. $db_name="sound";//database name
  37. $tbl_name="selection"; //table name
  38. $con=mysqli_connect("$host", "$username", "$password","$db_name")or die("cannot connect");//connection string
  39. $user=$_POST['userid'];
  40. $checkbox1=$_POST['videoid'];
  41. $chk="";
  42.  
  43. foreach($checkbox1 as $chk1)
  44. {
  45. $chk .= $chk1.",";
  46. }
  47. $in_ch=mysqli_query($con,"INSERT INTO tbl_selection (userid, videoid) VALUES ('$user', '$chk');");
  48. if($in_ch==1)
  49. {
  50. echo'<script>alert("Inserted Successfully")</script>';
  51. }
  52. else
  53. {
  54. echo'<script>alert("Failed To Insert")</script>';
  55. }
  56. }
  57. ?>
  58. </body>
  59. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement