Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- $host = '127.0.0.1';
- $db = 'cars';
- $username = 'carsinstock';
- $password = 'sellcars';
- $dbh = new PDO("mysql:host=$host;dbname=$db", $username, $password);
- ?>
- <!DOCTYPE html>
- <html>
- <head>
- <title>Fråga 2</title>
- </head>
- <body>
- <form action="/" method="POST">
- <input type="text" name="query" value="<?php if(isset($_POST['query'])){echo $_POST['query'];} ?>">
- <input type="submit" value="Sök">
- </form>
- <?php
- if (isset($_POST['query']))
- {
- $query = $_POST['query'];
- $sth = $dbh->prepare('SELECT regnr, fabrikat, modell FROM car WHERE fabrikat = :query');
- $sth->bindParam(':query', $query);
- $sth->execute();
- $results = $sth->fetchAll();
- foreach ($results as $result)
- {
- echo $result['regnr'];
- }
- }
- $sth = null;
- $dbh = null;
- ?>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement