Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="hu">
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>Webes Alkalmazás</title>
  6.  
  7. <link rel="stylesheet" type="text/css" href="src/style.css">
  8.  
  9. </head>
  10. <body>
  11.  
  12. <header>
  13. <h1>Szavazás</h1>
  14. </header>
  15.  
  16. <?php
  17. $dbHost = "localhost";
  18. $dbName = "zh3";
  19. $dbUser = "root";
  20. $dbPass = "";
  21.  
  22. $db = new PDO("mysql:host=".$dbHost.";dbname=".$dbName.";charset=utf8mb4;", $dbUser, $dbPass);
  23.  
  24. if (!empty($_POST)){
  25. $sql= "INSERT INTO vote VALUES (NULL, '".$_POST['type']."', '".$_POST['sex']."', ".$_POST['age'].")";
  26. $db->query($sql);
  27. }
  28.  
  29.  
  30. ?>
  31.  
  32. <main>
  33.  
  34. <section>
  35.  
  36. <h2>Szavazat leadása</h2>
  37.  
  38. <form method="post" action="">
  39. <label for="sex">Nem</label>
  40. <select name="sex" id="sex">
  41. <option value="m">Férfi</option>
  42. <option value="f">Nő</option>
  43. </select>
  44. <label for="age">Kor</label>
  45. <input type="number" value="18" name="age" id="age">
  46. <label for="type">Jelleg</label>
  47. <select name="type" id="type">
  48. <option value="1">Támogatom</option>
  49. <option value="0">Elutasítom</option>
  50. </select>
  51. <input type="submit" name="send" value="Beküldés">
  52. </form>
  53.  
  54. </section>
  55.  
  56. <section>
  57.  
  58. <h2>Szavazatok</h2>
  59.  
  60. <table>
  61. <thead>
  62. <tr>
  63. <th>Sorszám</th>
  64. <th>Szavazat jellege</th>
  65. <th>Nem</th>
  66. <th>Kor</th>
  67. </tr>
  68. </thead>
  69. <tbody>
  70. <?php
  71. $sql = "SELECT * FROM vote ORDER BY type DESC";
  72. $query = $db->query($sql);
  73. $result = $query->fetchAll();
  74.  
  75. for($i=0; $i<count($result); $i++){
  76. $id = $result[$i]['id'];
  77. $type=$result[$i]['type'];
  78. $sex=$result[$i]['sex'];
  79. $age=$result[$i]['age']." éves";
  80.  
  81. if($type == 1){
  82. $type = "Támogat";
  83. }else{
  84. $type = "Elutasít";
  85. }
  86. if($sex == 'm'){
  87. $sex = 'Férfi';
  88. }else{
  89. $sex = 'Nő';
  90. }
  91.  
  92.  
  93.  
  94. echo '
  95. <tr>
  96. <td>'.$id.'</td>
  97. <td>'.$type.'</td>
  98. <td>'.$sex.'</td>
  99. <td>'.$age.'</td>
  100. </tr>
  101. ';
  102. }
  103. ?>
  104. </tbody>
  105. </table>
  106.  
  107. </section>
  108.  
  109. </main>
  110.  
  111. </body>
  112. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement