kr_master
AJAX texnologiyasi orqali bazaga ma'lumot yuborish kodi

index.php

  1. <!DOCTYPE html>
  2. <form action="" method="POST">
  3. <input type="text" id="text">
  4. <button type="button" id="send">
  5. $("#send").click(function() {
  6. var text = $("#text").val();
  7. if (text != "") {
  8. $.ajax({
  9. type: "GET",
  10. url: "request.php",
  11. data: { text: text },
  12. cache: false,
  13. });
  14. }
  15. });
  16. </body>
  17. </html>


request.php

  1. <?php
  2. require("data.base.php");
  3. $text = htmlentities(strip_tags($_GET['text']));
  4. mysqli_query($connect, "INSERT INTO `messages`(`text`) VALUES ('$text')");


data.base.php

  1. <?php
  2. $dbhost = 'localhost';
  3. $dbname = 'name';
  4. $dbpass = 'password';
  5. $dbuser = 'user';
  6. $connect = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
  7. mysqli_set_charset($connect, "UTF-8");
  8. date_default_timezone_set('Asia/Tashkent');