Advertisement
Guest User

Untitled

a guest
Jun 18th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.18 KB | None | 0 0
  1. <?php
  2. --------------------------------------------------------------------------
  3. DATABASE
  4. --------------------------------------------------------------------------
  5. $host = 'localhost';
  6. $username = 'root';
  7. $password = 'root';
  8. $database = 'db1';
  9. $connection = mysqli_connect($host, $username, $password, $database);
  10.  
  11. if (mysqli_connect_error($connection)) die('Error connecting');
  12.  
  13. $emri = 'erald';
  14. $mbiemri = 'domi';
  15. if (!mysqli_query($connection, "INSERT INTO users (emri, mbiemri) VALUES ($emri, $mbiemri)")) die('Error adding user.');
  16.  
  17. $result = mysqli_query($connection, "SELECT * FROM users;");
  18. if (mysqli_num_rows($result) > 0) {
  19.     while ($row = mysqli_fetch_assoc($connection, $result)) {
  20.         echo $row['emri'] . ' ' . $row['mbiemri'];
  21.     }
  22. }
  23. mysqli_close($connection);
  24. --------------------------------------------------------------------------
  25. AJAX
  26. --------------------------------------------------------------------------
  27. ?>
  28.  
  29. var req = new XMLHttpRequest();
  30. req.onreadystatechange = function () {
  31.     if (this.readyState == 4 && this.status == 200) {
  32.         document.getElementById('filan_id').innerHTML = this.responseText;
  33.     }
  34. }
  35. req.open('GET', 'url', true);
  36. req.send();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement