Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- HTML.PHP
- <!DOCTYPE html>
- <html>
- <?php
- require_once('connect.php');
- ?>
- <head>
- <title>DATACZASZ SIEMA</title>
- <meta charset="utf-8">
- <script src="http://code.jquery.com/jquery-latest.min.js"></script>
- <script type="text/javascript" src="index.js"></script>
- </head>
- <body>
- <form>
- <div class="element" id="data"></div>
- <div id="divText"></div>
- <button type="button" id="wyslij">Dodaj</button>
- </form>
- </body>
- </html>
- INDEX.JS
- document.addEventListener("DOMContentLoaded", function() {
- var interwal = setInterval(pokazdik, 1000);
- function pokazdik() {
- const now = new Date();
- const el = document.querySelector(".element");
- el.innerText = `
- ${now.getHours()} : ${now.getMinutes()} : ${now.getSeconds()}
- ${now.getDate()} . ${now.getMonth()+1} . ${now.getFullYear()}
- `
- }
- $('#wyslij').click(function(){
- // var wartosc_daty = $('#data').val();
- var wartosc_daty = $('el').innerText;
- $.ajax({
- type:"POST",
- url: "wyslij.php",
- data:{klucz_ajax : wartosc_daty},
- success: function() {
- alert("Udalo sie");
- $("#wyslij").attr("disabled", true);
- setTimeout(function(){
- $("#wyslij").attr("disabled", false);
- }, 10000);
- },
- error : function(blad) {
- alert("Blad");
- console.log(blad);
- }
- });
- });
- });
- WYSLIJ.PHP
- <?php
- require 'connect.php';
- $wartosc_formularza = $_POST['klucz_ajax'];
- $zapytanie_wyslij = "INSERT INTO data (dataczas) VALUES ('$wartosc_formularza')";
- $wynik_wyslij = mysqli_query( $conn, $zapytanie_wyslij);
- ?>
- CONNECT.PHP
- <?php
- $host = 'localhost';
- $user = 'root';
- $haslo = '';
- $baza = 'data';
- $conn = mysqli_connect($host, $user, $haslo, $baza);
- if(mysqli_connect_errno())
- {
- echo 'bÅÄ d';
- exit;
- }
- else{
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement