Advertisement
Guest User

Untitled

a guest
Jan 12th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.80 KB | None | 0 0
  1. <?php
  2. $host = '127.0.0.1';
  3. $db = 'cars';
  4. $username = 'carsinstock';
  5. $password = 'sellcars';
  6. $dbh = new PDO("mysql:host=$host;dbname=$db", $username, $password);
  7. ?>
  8.  
  9. <!DOCTYPE html>
  10. <html>
  11. <head>
  12.     <title>Fråga 2</title>
  13. </head>
  14. <body>
  15.     <form action="/" method="POST">
  16.         <input type="text" name="query" value="<?php if(isset($_POST['query'])){echo $_POST['query'];} ?>">
  17.         <input type="submit" value="Sök">
  18.     </form>
  19.  
  20.     <?php
  21.     if (isset($_POST['query']))
  22.     {
  23.         $query = $_POST['query'];
  24.         $sth = $dbh->prepare('SELECT regnr, fabrikat, modell FROM car WHERE fabrikat = :query');
  25.         $sth->bindParam(':query', $query);
  26.         $sth->execute();
  27.         $results = $sth->fetchAll();
  28.  
  29.         foreach ($results as $result)
  30.         {
  31.             echo $result['regnr'];
  32.         }
  33.     }
  34.  
  35.     $sth = null;
  36.     $dbh = null;
  37.     ?>
  38.  
  39. </body>
  40. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement