Advertisement
abedkowski

Untitled

Dec 14th, 2018
134
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.92 KB | None | 0 0
  1. <?php
  2. $text = $_POST["text"];
  3. $select = $_POST["select"];
  4. $servername = "localhost";
  5. $username = "root";
  6. $password = "";
  7. $dbname = "Studenci";
  8.  
  9. // Create connection
  10. $conn = new mysqli($servername, $username, $password, $dbname);
  11. // Check connection
  12. if ($conn->connect_error) {
  13.     die("Connection failed: " . $conn->connect_error);
  14. }
  15. if($select=="*")
  16. {
  17.     $sql = "SELECT * FROM Studenci";
  18. }
  19. if($select=="imie")
  20. {
  21.     $sql = "SELECT id, imie, nazwisko FROM Studenci WHERE imie='" . $text . "'";
  22. }
  23. if($select=="nazwisko")
  24. {
  25.     $sql = "SELECT id, imie, nazwisko FROM Studenci WHERE nazwisko='" . $text . "'";
  26. }
  27.  
  28.  
  29. $result = $conn->query($sql);
  30.  
  31. if ($result->num_rows > 0) {
  32.     // output data of each row
  33.     while($row = $result->fetch_assoc()) {
  34.         echo "id: " . $row["id"]. " - Imie: " . $row["imie"]. " - Nazwisko: " . $row["nazwisko"]. "<br>";
  35.     }
  36. } else {
  37.     echo "0 wyników";
  38. }
  39. $conn->close();
  40. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement