Advertisement
Guest User

belajar

a guest
Sep 6th, 2018
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. <html>
  2. <body>
  3. <form action="" method="post" enctype="multipart/form-data">
  4. <div style="width:200px;border-radius:6px;margin:0px auto">
  5. <table border="1">
  6. <tr>
  7. <td colspan="2">1. Buah :</td>
  8. </tr>
  9. <tr>
  10. <td>Jeruk</td>
  11. <td><input type="checkbox" name="buah[]" value="Jeruk"></td>
  12. </tr>
  13. <tr>
  14. <td>Apel</td>
  15. <td><input type="checkbox" name="buah[]" value="Apel"></td>
  16. </tr>
  17. <tr>
  18. <td>Semangka</td>
  19. <td><input type="checkbox" name="buah[]" value="Semangka"></td>
  20. </tr>
  21. <tr>
  22. <td>Melon</td>
  23. <td><input type="checkbox" name="buah[]" value="Melon"></td>
  24. </tr>
  25. <tr>
  26. <td colspan="2">2. Minum :</td>
  27. </tr>
  28. <tr>
  29. <td>Es Jeruk</td>
  30. <td><input type="checkbox" name="minum[]" value="Es Jeruk"></td>
  31. </tr>
  32. <tr>
  33. <td>Es Apel</td>
  34. <td><input type="checkbox" name="minum[]" value="Es Apel"></td>
  35. </tr>
  36. <tr>
  37. <td colspan="2" align="center"><input type="submit" value="submit" name="sub"></td>
  38. </tr>
  39. </table>
  40. </div>
  41. </form>
  42. <?php
  43. if(isset($_POST['sub']))
  44. {
  45. $host="localhost";//host name
  46. $username="root"; //database username
  47. $pass="";//database password
  48. $db_name="drp";//database name
  49. $tbl_name="coba"; //table name
  50. $con=mysqli_connect("$host", "$username", "$pass","$db_name")or die("cannot connect");//connection string
  51. $checkbox1=$_POST['buah'];
  52. $chk="";
  53. foreach($checkbox1 as $chk1)
  54. {
  55. $chk .= $chk1.",";
  56. }
  57. $in_ch=mysqli_query($con,"insert into coba(buah) values ('$chk')");
  58.  
  59. if($in_ch==1)
  60. {
  61. echo'<script>alert("Inserted Successfully")</script>';
  62. }
  63. else
  64. {
  65. echo'<script>alert("Failed To Insert")</script>';
  66. }
  67. }
  68. ?>
  69. </body>
  70. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement