kr_master
AJAX texnologiyasi orqali bazaga ma'lumot yuborish kodi

index.php

Kod · HTML41 qator
<!DOCTYPE html>

<html>

<body>

<form action="" method="POST">

<input type="text" id="text">

<button type="button" id="send">

<script>

$("#send").click(function() {

        var text = $("#text").val();

        if (text != "") {

            $.ajax({

                type: "GET",

                url: "request.php",

                data: { text: text },

                cache: false,

            });

        }

    });

</script>

</body>

</html>


request.php

Kod · PHP7 qator
<?php

require("data.base.php");

$text = htmlentities(strip_tags($_GET['text']));

mysqli_query($connect, "INSERT INTO `messages`(`text`) VALUES ('$text')");


data.base.php

Kod · PHP15 qator
<?php

$dbhost = 'localhost';

$dbname = 'name';

$dbpass = 'password';

$dbuser = 'user';

$connect = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);

mysqli_set_charset($connect, "UTF-8");

date_default_timezone_set('Asia/Tashkent');