Advertisement
Guest User

Zadanie

a guest
Feb 19th, 2020
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. HTML.PHP
  2.  
  3. <!DOCTYPE html>
  4. <html>
  5. <?php
  6. require_once('connect.php');
  7.  
  8. ?>
  9. <head>
  10. <title>DATACZASZ SIEMA</title>
  11. <meta charset="utf-8">
  12. <script src="http://code.jquery.com/jquery-latest.min.js"></script>
  13. <script type="text/javascript" src="index.js"></script>
  14.  
  15. </head>
  16. <body>
  17.  
  18. <form>
  19. <div class="element" id="data"></div>
  20. <div id="divText"></div>
  21. <button type="button" id="wyslij">Dodaj</button>
  22. </form>
  23. </body>
  24. </html>
  25.  
  26. INDEX.JS
  27.  
  28. document.addEventListener("DOMContentLoaded", function() {
  29.  
  30. var interwal = setInterval(pokazdik, 1000);
  31.  
  32. function pokazdik() {
  33. const now = new Date();
  34. const el = document.querySelector(".element");
  35. el.innerText = `
  36. ${now.getHours()} : ${now.getMinutes()} : ${now.getSeconds()}
  37. ${now.getDate()} . ${now.getMonth()+1} . ${now.getFullYear()}
  38. `
  39.  
  40. }
  41.  
  42. $('#wyslij').click(function(){
  43.  
  44. // var wartosc_daty = $('#data').val();
  45. var wartosc_daty = $('el').innerText;
  46. $.ajax({
  47. type:"POST",
  48. url: "wyslij.php",
  49. data:{klucz_ajax : wartosc_daty},
  50.  
  51. success: function() {
  52. alert("Udalo sie");
  53.  
  54. $("#wyslij").attr("disabled", true);
  55. setTimeout(function(){
  56. $("#wyslij").attr("disabled", false);
  57. }, 10000);
  58. },
  59. error : function(blad) {
  60. alert("Blad");
  61. console.log(blad);
  62. }
  63. });
  64. });
  65. });
  66.  
  67.  
  68. WYSLIJ.PHP
  69.  
  70.  
  71. <?php
  72.  
  73. require 'connect.php';
  74. $wartosc_formularza = $_POST['klucz_ajax'];
  75. $zapytanie_wyslij = "INSERT INTO data (dataczas) VALUES ('$wartosc_formularza')";
  76. $wynik_wyslij = mysqli_query( $conn, $zapytanie_wyslij);
  77.  
  78. ?>
  79.  
  80. CONNECT.PHP
  81.  
  82. <?php
  83.  
  84. $host = 'localhost';
  85. $user = 'root';
  86. $haslo = '';
  87. $baza = 'data';
  88.  
  89. $conn = mysqli_connect($host, $user, $haslo, $baza);
  90. if(mysqli_connect_errno())
  91. {
  92. echo 'błąd';
  93. exit;
  94. }
  95. else{
  96.  
  97. }
  98. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement