Advertisement
Guest User

Untitled

a guest
Jan 28th, 2019
154
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.89 KB | None | 0 0
  1. <?php
  2. date_default_timezone_set('Asia/Hong_Kong');
  3. ini_set('error_log', 'logfile.txt');
  4.  
  5. //Sets database connection information
  6. if (!(strpos($_SERVER["SERVER_NAME"], "localhost") === false)) {
  7. $hostname="localhost" ;
  8. $username="root" ;
  9. $password="root" ;
  10. $database="club" ;
  11. }
  12.  
  13. try {
  14. $dbh = new PDO("mysql:host=$hostname;
  15. dbname=$database;
  16. charset=utf8", $username, $password
  17. );
  18. $dbh->setAttribute(PDO::MYSQL_ATTR_USE_BUFFERED_QUERY, true);
  19. $dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  20. } catch (PDOException $e) {
  21. print "Error!: " . $e->getMessage() . "<br/>";
  22. die();
  23. }
  24.  
  25. $sql = "SELECT DISTINCT sport FROM `club`
  26. ORDER BY sport";
  27. $rs = $dbh->prepare($sql);
  28. $rs->execute();
  29. $sportList = $rs->fetchAll(PDO::FETCH_ASSOC);
  30. print_r($sportList);
  31.  
  32. $data = array(
  33. "sport" => "rugby",
  34. "familyName" => "Parker-Rauw"
  35. );
  36. $sql = "SELECT * FROM club WHERE sport = :sport AND familyname = :familyName";
  37. $rs = $dbh->prepare($sql);
  38. $rs->execute($data);
  39.  
  40. while ($row = $rs->fetch()) {
  41. print_r($row);
  42. print "<br>";
  43. }
  44. ?>
  45. <!DOCTYPE html>
  46. <!--
  47. To change this license header, choose License Headers in Project Properties.
  48. To change this template file, choose Tools | Templates
  49. and open the template in the editor.
  50. -->
  51. <html>
  52. <head>
  53. <meta charset="UTF-8">
  54. <title></title>
  55. </head>
  56. <body>
  57. <?php
  58. echo "<form name='filter' method='post' action=''>";
  59. echo "<select name='sport'>";
  60. for($i=0; $i<count($sportList); $i++) {
  61. echo "<option value='".$sportList[$i]["sport"]."'>".$sportList[$i]["sport"]."</option>";
  62. }
  63. echo "</select>";
  64. echo "<input type='submit' name='submitFilter' value='Go' />";
  65. echo "</form>";
  66. // put your code here
  67. ?>
  68. </body>
  69. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement