Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!DOCTYPE html>
- <html lang="hu">
- <head>
- <meta charset="UTF-8">
- <title>Webes Alkalmazás</title>
- <link rel="stylesheet" type="text/css" href="src/style.css">
- </head>
- <body>
- <header>
- <h1>Szavazás</h1>
- </header>
- <?php
- $dbHost = "localhost";
- $dbName = "zh3";
- $dbUser = "root";
- $dbPass = "";
- $db = new PDO("mysql:host=".$dbHost.";dbname=".$dbName.";charset=utf8mb4;", $dbUser, $dbPass);
- if (!empty($_POST)){
- $sql= "INSERT INTO vote VALUES (NULL, '".$_POST['type']."', '".$_POST['sex']."', ".$_POST['age'].")";
- $db->query($sql);
- }
- ?>
- <main>
- <section>
- <h2>Szavazat leadása</h2>
- <form method="post" action="">
- <label for="sex">Nem</label>
- <select name="sex" id="sex">
- <option value="m">Férfi</option>
- <option value="f">Nő</option>
- </select>
- <label for="age">Kor</label>
- <input type="number" value="18" name="age" id="age">
- <label for="type">Jelleg</label>
- <select name="type" id="type">
- <option value="1">Támogatom</option>
- <option value="0">Elutasítom</option>
- </select>
- <input type="submit" name="send" value="Beküldés">
- </form>
- </section>
- <section>
- <h2>Szavazatok</h2>
- <table>
- <thead>
- <tr>
- <th>Sorszám</th>
- <th>Szavazat jellege</th>
- <th>Nem</th>
- <th>Kor</th>
- </tr>
- </thead>
- <tbody>
- <?php
- $sql = "SELECT * FROM vote ORDER BY type DESC";
- $query = $db->query($sql);
- $result = $query->fetchAll();
- for($i=0; $i<count($result); $i++){
- $id = $result[$i]['id'];
- $type=$result[$i]['type'];
- $sex=$result[$i]['sex'];
- $age=$result[$i]['age']." éves";
- if($type == 1){
- $type = "Támogat";
- }else{
- $type = "Elutasít";
- }
- if($sex == 'm'){
- $sex = 'Férfi';
- }else{
- $sex = 'Nő';
- }
- echo '
- <tr>
- <td>'.$id.'</td>
- <td>'.$type.'</td>
- <td>'.$sex.'</td>
- <td>'.$age.'</td>
- </tr>
- ';
- }
- ?>
- </tbody>
- </table>
- </section>
- </main>
- </body>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement