Advertisement
Guest User

Untitled

a guest
Jan 11th, 2017
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.07 KB | None | 0 0
  1. <?php
  2. header('Content-Type: text/html; charset=utf-8');
  3.  
  4. $hostname='localhost';
  5. $username='root';
  6. $password='';
  7.  
  8. try {
  9. $dbh = new PDO("mysql:host=$hostname;dbname=edustart;charset=utf8",$username,$password);
  10.  
  11. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); // <== add this line
  12. //echo '<em>Connected to Database</em><br><br>';
  13. }
  14. catch(PDOException $e)
  15. {
  16. echo $e->getMessage();
  17. }
  18.  
  19. if(isset($_POST["query"]))
  20.  
  21. {
  22. $output = '';
  23. $query = "SELECT * FROM edu_schools WHERE school_name LIKE '%".$_POST["query"]."%' AND school_type = 'vgs'";
  24. $sql = $dbh->prepare($query);
  25. $sql->execute();
  26. $output = '<ul>';
  27. $numrows = $sql->rowCount();
  28. if($numrows > 0)
  29. {
  30. while($row = $sql->fetch(PDO::FETCH_ASSOC))
  31. {
  32. $output .= '<li>'.$row["school_name"].'</li>';
  33. }
  34. }
  35. else
  36. {
  37. $output .= '<li>Finner ikke skolen</li>';
  38. }
  39. $output .= '</ul>';
  40. echo $output;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement