Apa itu pemilih tanggal php?

Pemilih Tanggal PHP

Apa itu pemilih tanggal php?

Pemilih tanggal bergaya kalender sederhana untuk menavigasi halaman acara dan sejenisnya

tests/test.html.php_, tes fungsional, menunjukkan kepada Anda bagaimana Anda dapat mengintegrasikan kalender

Lembar gaya CSS pemula, yang digunakan oleh pengujian fungsional, dapat ditemukan di assets/css/picker.css

Referensi

Awalnya diposting @ https. // kode dan terapkan. com kunjungi dan unduh kode sampel. https. // kode dan terapkan. com/blog/php/cara-menggunakan-bootstrap-datepicker-in-php-mysql-using-ajax

Dalam tutorial ini, saya akan menjelaskan cara mengimplementasikan Bootstrap Datepicker di PHP & MySQL menggunakan Ajax. Saya akan memandu Anda langkah demi langkah tentang cara kerjanya. Jadi dalam contoh ini, kita akan membuat sebuah fungsi yang menanyakan pengguna tentang tanggal lahir mereka

Dengan bantuan Bootstrap Datepicker, kami mengaktifkan proses cepat dengan antarmuka pengguna yang luar biasa alih-alih melakukannya dari awal atau hanya menggunakan pemilih tanggal asli di chrome yang tidak mendukung browser lain

Apa itu pemilih tanggal php?

Jadi sebelum kita melanjutkan tutorial ini, saya akan memberi tahu Anda bahwa kami menggunakan Bootstrap 4, jQuery 3. 5. 1, dan Bootstrap Datepicker

Indeks. html

Berikut adalah kode sumber lengkap dari index. html

<!doctype html>
<html lang="en">
<head>
    <title>How To Use Bootstrap Datepicker in PHP & MySQL using Ajax</title>

    <!-- Bootstrap CSS -->
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
    <!-- Bootstra Datepicker CSS -->
    <link rel="stylesheet" href="assets/plugins/bootstrap-datepicker/css/bootstrap-datepicker.min.css">

</head>

<body>

    <div class="container">

        <br><br>

        <h1>How To Use Bootstrap Datepicker in PHP & MySQL using Ajax</h1>

        <br><br>

        <form action="process.php" id="form">
            <div class="form-group">
                <label for="email">Date Of Birth:</label>
                <input class="date form-control" type="text" name="date-of-birth">
            </div>
            <button type="button" class="btn btn-primary" id="btnSubmit">Submit</button>
        </form>
    </div>

    <!-- Must put our javascript files here to fast the page loading -->

    <!-- jQuery library -->
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <!-- Popper JS -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
    <!-- Bootstrap JS -->
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>
    <!-- Bootstrap Datepicker JS -->
    <script src="assets/plugins/bootstrap-datepicker/js/bootstrap-datepicker.min.js"></script>
    <!-- Page Script -->
    <script src="assets/js/scripts.js"></script>

</body>

</html>

Masuk ke mode layar penuh Keluar dari mode layar penuh

Naskah. File js

Selanjutnya, javascript kami disebut skrip. js dari mengimpor kode di atas. Silakan periksa komentar setiap baris agar Anda memahami prosesnya

$(document).ready(function() {

    // Initialize the datepicker
    $('.date').datepicker({
        todayHighlight: true, // to highlight the today's date
        format: 'yyyy-mm-dd', // we format the date before we will submit it to the server side
        autoclose: true //we enable autoclose so that once we click the date it will automatically close the datepicker
    }); 

    $("#btnSubmit").on("click", function() {
        var $this           = $("#btnSubmit"); //submit button selector using ID
        var $caption        = $this.html();// We store the html content of the submit button
        var form            = "#form"; //defined the #form ID
        var formData        = $(form).serializeArray(); //serialize the form into array
        var route           = $(form).attr('action'); //get the route using attribute action

        // Ajax config
        $.ajax({
            type: "POST", //we are using POST method to submit the data to the server side
            url: route, // get the route value
            data: formData, // our serialized array data for server side
            beforeSend: function () {//We add this before send to disable the button once we submit it so that we prevent the multiple click
                $this.attr('disabled', true).html("Processing...");
            },
            success: function (response) {//once the request successfully process to the server side it will return result here
                $this.attr('disabled', false).html($caption);
                // We will display the result using alert
                alert(response);
            },
            error: function (XMLHttpRequest, textStatus, errorThrown) {
                // You can put something here if there is an error from submitted request
            }
        });
    });


});
_

Masuk ke mode layar penuh Keluar dari mode layar penuh

Membuat Tabel Database

Selanjutnya, buat tabel database kita. Jika Anda sudah membuat database Anda maka kami akan terus membuat tabel kami "dob" sebagai nama tabel Anda. Berikut adalah kode di bawah ini

CREATE TABLE `dob` (
  `id` int(11) NOT NULL,
  `dob` date NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Masuk ke mode layar penuh Keluar dari mode layar penuh

Proses. File php

Selanjutnya, kode terakhir kita untuk memproses penyimpanan data yang dikirimkan dari kita

<?php
    $request = $_REQUEST; //a PHP Super Global variable which used to collect data after submitting it from the form
    $date = $request['date-of-birth']; //get the date of birth from collected data above

    $servername = "localhost"; //set the servername
    $username = "root"; //set the server username
    $password = ""; // set the server password (you must put password here if your using live server)
    $dbname = "demos"; // set the table name

    // Create connection
    $conn = mysqli_connect($servername, $username, $password, $dbname);
    // Check connection
    if (!$conn) {
      die("Connection failed: " . mysqli_connect_error());
    }

    // Set the INSERT SQL data
    $sql = "INSERT INTO dob (dob)
    VALUES ('".$date."')";

    // Process the query so that we will save the date of birth
    if (mysqli_query($conn, $sql)) {
      echo "New record created successfully.";
    } else {
      return "Error: " . $sql . "<br>" . mysqli_error($conn);
    }

    // Close the connection after using it
    mysqli_close($conn);
?>

Masuk ke mode layar penuh Keluar dari mode layar penuh

Sekarang Anda dapat mengaktifkan untuk menyimpan data dari formulir dengan bootstrap datepicker menggunakan PHP dan MySQL dengan Ajax

Saya harap tutorial ini dapat membantu Anda. Silakan kunjungi di sini https. // kode dan terapkan. com/blog/php/how-to-use-bootstrap-datepicker-in-php-mysql-using-ajax jika Anda ingin mengunduh kode ini

Apa itu DatePicker di php?

EJ DatePicker menyediakan API tempat Anda dapat menyetel nilai tanggal maksimum dan minimum yang diizinkan . Nilai tanggal Min dan Max dapat diatur pada inisialisasi seperti yang ditunjukkan di bawah ini.

Apa gunanya pemilih tanggal?

Pemilih Tanggal Android memungkinkan Anda memilih tanggal yang terdiri dari hari, bulan, dan tahun di antarmuka pengguna khusus Anda . Untuk fungsi ini android menyediakan komponen DatePicker dan DatePickerDialog.

Bagaimana cara menambahkan pemilih tanggal dan waktu di php?

Setel tanggal waktu menggunakan kode ini. $('#datetimepickerDemo'). datetimepicker({ format. "d-M-yy h. mm tt") }); $('#datetimepickerDemo').

Apa pemilih tanggal dalam HTML?

defines a date picker . Nilai yang dihasilkan meliputi tahun, bulan, dan hari. Tip. Selalu tambahkan tag