Advertisement
Guest User

Untitled

a guest
Feb 25th, 2019
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. <button type="button" class="btn btn-block btn-primary" data-toggle="modal" data-target="#dataModal"></button>
  2.  
  3. <!-- Modal -->
  4. <div class="modal fade" id="dataModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel" aria-hidden="true">
  5. <div class="modal-dialog modal-lg" role="document">
  6. <div class="modal-content">
  7. <div class="modal-header">
  8. <h5 class="modal-title" >Adicionar dados</h5>
  9. <button type="button" class="close" data-dismiss="modal" aria-label="Close">
  10. <span aria-hidden="true">×</span>
  11. </button>
  12. </div>
  13.  
  14. <div class="modal-body">
  15.  
  16. <form id="usersform" method="post">
  17. <input type="text" name="nome" id="nome"/>
  18. <input type="email" name="email" id="email"/>
  19. </div>
  20. <div class="modal-footer">
  21. <button type="button" class="btn btn-secondary" data-dismiss="modal">CANCELAR</button>
  22. <button type="submit" class="btn btn-success" id="submit" >ADD USER</button>
  23. </form>
  24. </div>
  25. </div>
  26. </div>
  27. </div>
  28.  
  29. <script>
  30.  
  31. $(document).on('submit', '#usersform', function(event){
  32. event.preventDefault();
  33. $.ajax({
  34. url:"insert.php",
  35. method:'POST',
  36. data:new FormData(this),
  37. contentType:false,
  38. processData:false,
  39. success:function(data){
  40. alert("Cadastro realizado com sucesso!");
  41. $("#usersform")[0].reset();
  42. $("#dataModal").modal('hide');
  43.  
  44. }
  45. });
  46. });
  47.  
  48. </script>
  49.  
  50. <?php
  51. $servername = "localhost";
  52. $username = "root";
  53. $password = "";
  54. $dbname = "system";
  55.  
  56. // Create connection
  57. $conn = mysqli_connect($servername, $username, $password, $dbname);
  58. // Check connection
  59. if (!$conn) {
  60. die("Connection failed: " . mysqli_connect_error());
  61. }
  62. $nome = $_POST['nome'];
  63. $email = $_POST['email'];
  64. $sql = "INSERT INTO users (nome,email)
  65. VALUES ('$nome', '$email')";
  66.  
  67. if (mysqli_query($conn, $sql)) {
  68. echo "New record created successfully";
  69. } else {
  70. echo "Error: " . $sql . "<br>" . mysqli_error($conn);
  71. }
  72.  
  73. mysqli_close($conn);
  74.  
  75. ?>
  76.  
  77. $("#dataModal").modal('hide');
  78.  
  79. $("#dataModal").hide();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement