Guest User

Untitled

a guest
Nov 5th, 2017
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.74 KB | None | 0 0
  1. <?php
  2.  
  3. $servername = "localhost";
  4. $user = "root";
  5. $pass = "test";
  6. $dbname = "test";
  7.  
  8. // Create Connection
  9. $conn = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
  10.  
  11. //check Connection
  12. // if ($conn->connect_error) {
  13. // die("Connection failed: ". $conn->connect_error);
  14. //}
  15.  
  16. //Run Query
  17. $query = 'SELECT ort FROM test3';
  18. $result = $conn->prepare($query);
  19. $result->execute();
  20. $data = $result->fetchAll();
  21.  
  22. ?>
  23.  
  24. <!DOCTYPE html>
  25. <html>
  26. <head>
  27. <title>Dropdown</title>
  28. </head>
  29. <body>
  30. <div class="city">
  31. <label>Stadt</label>
  32. <select name="city">
  33. <option value="">Wähle eine Stadt</option>
  34. <!-- populate using php -->
  35. <?php foreach ($data as $row): ?>
  36.  
  37. <option value=""><?=$row["ort"]?></option>
  38. <?php endforeach ?>
  39. </select>
  40. </div>
  41. </body>
  42. </html>
Add Comment
Please, Sign In to add comment