Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Dynamiczna lista
kolorek1
post
Post #1





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 17.08.2017

Ostrzeżenie: (0%)
-----


Witajcie.
Bardzo proszę o pomoc. Na mojej stronie chcę zrobić coś takiego, że po wpisaniu załóżmy 3 znaków z emaila podpowiadało mi niżej użytkownika pobranego z bazy "x" z tabeli "db_users". Mógłby ktoś pomóc mi to zrobić?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
kolorek1
post
Post #2





Grupa: Zarejestrowani
Postów: 6
Pomógł: 0
Dołączył: 17.08.2017

Ostrzeżenie: (0%)
-----


Ja to rozumiem tak..
  1. <?php
  2. header("Content-Type: application/json;charset=utf-8");
  3.  
  4. $userId = (int) $_POST['userid'];
  5. $action = $_POST['action'] (IMG:style_emoticons/default/questionmark.gif) null;
  6.  
  7. if ($action === 'select') {
  8. try {
  9. $dbh = new PDO('mysql:dbname=test;tutaj wpisuje host bazy', 'user', 'pass', [
  10. PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"
  11. ]
  12. );
  13. $dbh->setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION );
  14. $sql = "DELETE FROM users WHERE user_id = ?";
  15. $sth = $dbh->prepare($sql);
  16. $sth->execute([$tutaj zmieniam na nazwe komórki np db_users]);
  17. echo json_encode([
  18. 'message' => sprintf('Skasowano %d rekordów', $sth->rowCount())
  19. ]);
  20. } catch(PDOException $e) {
  21. http_response_code(500);
  22. echo json_encode([
  23. 'message' => 'Klasa PDO zwróciła wyjątek: ' . $e->getMessage()
  24. ]);
  25. }
  26. } else {
  27. http_response_code(500);
  28. echo json_encode([
  29. 'message' => 'Nieprawidłowa akcja'
  30. ]);
  31. }
  32.  


Następnie
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
  6. <script>
  7. $(function() {
  8. $('#userdelete').on('submit', function(event) {
  9. event.preventDefault();
  10. $.ajax({
  11. url: "user_ajax.php",
  12. method: "POST",
  13. data: $(this).serialize()
  14. })
  15. .done(function(data, textStatus, jqXHR) {
  16. $('#message').html(data.message);
  17. })
  18. .fail(function(jqXHR, textStatus, errorThrown) {
  19. $('#message').html(jqXHR.responseJSON.message);
  20. });
  21. });
  22. });
  23. </script>
  24. </head>
  25. <body>
  26. <div id="message"></div>
  27. <form action="POST" id="userdelete">
  28. <input type="text" name="nazwa komóki tabeli np db_users">
  29. <input type="hidden" name="action" value="select">
  30. <input type="change">
  31. </form>
  32. </body>
  33. </html>
Go to the top of the page
+Quote Post

Posty w temacie


Reply to this topicStart new topic
2 Użytkowników czyta ten temat (2 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Aktualny czas: 17.10.2025 - 16:10