Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $servername = "localhost";
- $user = "root";
- $pass = "test";
- $dbname = "test";
- // Create Connection
- $conn = new PDO('mysql:host=localhost;dbname=test', $user, $pass);
- //check Connection
- // if ($conn->connect_error) {
- // die("Connection failed: ". $conn->connect_error);
- //}
- //Run Query
- $query = 'SELECT ort FROM test3';
- $result = $conn->prepare($query);
- $result->execute();
- $data = $result->fetchAll();
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Dropdown</title>
- </head>
- <body>
- <div class="city">
- <label>Stadt</label>
- <select name="city">
- <option value="">Wähle eine Stadt</option>
- <!-- populate using php -->
- <?php foreach ($data as $row): ?>
- <option value=""><?=$row["ort"]?></option>
- <?php endforeach ?>
- </select>
- </div>
- </body>
- </html>
Add Comment
Please, Sign In to add comment