· 9 years ago · Oct 07, 2016, 06:30 AM
1<!DOCTYPE html>
2<html>
3<head>
4 <meta charset="utf-8">
5 <title>Stránka</title>
6 <style type="text/css">
7 body {
8 background-color:#CCC2FF;
9 }
10.ahoj{
11 font-size : 12px;
12 color : #b1b1b1;
13 font-family:Arial;
14 text-align: center;
15 border-top: 3px solid #ff8400;
16 background-color : #363636;
17}
18tr:nth-child(2n){
19background-color:#404040;
20}
21
22 </style>
23</head>
24<body>
25<?php
26$true = true;
27$false = false;
28$cau = mysqli_connect("localhost","4vt2016","4vt*2016","4vt2016") or die("CHYBA V SPOJENI");
29//mysqli_query($cau, "DROP TABLE valentik_test_armadni_technika");
30if (mysqli_num_rows(mysqli_query($cau,"SHOW TABLES LIKE 'valentik_test_armadni_technika'")) == 0){
31$dotaz = "CREATE TABLE IF NOT EXISTS `valentik_test_armadni_technika` (
32 `cislo_polozky` int NOT NULL AUTO_INCREMENT PRIMARY KEY,
33 `nazev_techniky` varchar(255),
34 `technika` varchar(255),
35 `druh` tinyint(1) NOT NULL)";
36 if(isset($_POST['vytvorit'])) {
37 $result = mysqli_query($cau,$dotaz);
38 if($result) {
39 echo "<meta http-equiv='refresh' content='1; url=http://192.168.1.235/~Valentik/vytvoreni_databaze.php/' />";
40 echo "vytvoreno";
41 } else {
42 echo "chyba";
43 }
44 }
45echo "<form method='post'>";
46echo "<input type='submit' value='vytvořit tabulku' name='vytvorit'>";
47echo "</form>";
48} else {
49if(isset($_POST['pridat'])) {
50if(empty($_POST['_nazev']) or empty($_POST['_technika'])) {
51echo "Vyplň povinná pole";
52} else {
53echo "<BR>Záznam úspěšně vložen";
54echo "<meta http-equiv='refresh' content='1; url=http://192.168.1.235/~Valentik/vytvoreni_databaze.php/' />";
55$result = mysqli_query($cau,"INSERT INTO valentik_test_armadni_technika(nazev_techniky,technika, druh) VALUES('".htmlspecialchars($_POST['_nazev'])."','".htmlspecialchars($_POST['_technika'])."','".htmlspecialchars($_POST['technika'])."')");
56}
57}
58 echo "<form method='POST' align='center'>";
59 echo "<input type='radio' name='druh' value='1' checked> Vzdušná - <input type='radio' name='druh' value='0'> Pozemni";
60 echo "<input type='submit' value='Zobrazit' name='_show'>";
61 echo "</form>";
62 echo "<BR>";
63 if(isset($_POST['_show'])) {
64 if($_POST['druh'] == true) {
65 $result = mysqli_query($cau, "SELECT * FROM valentik_test_armadni_technika WHERE druh='".$true."'");
66 } else {
67 $result = mysqli_query($cau, "SELECT * FROM valentik_test_armadni_technika WHERE druh='".$false."'");
68 }
69 } else
70 $result = mysqli_query($cau, "SELECT * FROM valentik_test_armadni_technika");
71 echo "<table align='center' width='50%' class='ahoj'>";
72 echo "<tr style='font-size:20px;color:#ff8400;'>";
73 echo "<td>Název techniky</td>";
74 echo "<td>tank/vrtulnÃk/loÄ</td>";
75 echo "<td>PozemnÃ/vzduÅ¡ná</td>";
76 echo "</tr>";
77 while($data = mysqli_fetch_assoc($result)) {
78 echo "<tr>";
79 echo "<td>".$data['nazev_techniky']."</td>";
80 echo "<td>".$data['technika']."</td>";
81 if($data['druh'] == false)
82 echo "<td>pozemnÃ</td>";
83 else
84 echo "<td>vzdušná</td>";
85 echo "</tr>";
86 }
87 echo "</table>";
88 echo "<form method='post' class='table_form'>";
89 echo "<table align='center'>";
90 echo "<tr style='background-color:#ccc2ff;'>";
91 echo "<td>Název techniky: </td> <td><input type='text' name='_nazev' placeholder='Název techniky'></td>";
92 echo "</tr>";
93 echo "<tr style='background-color:#ccc2ff;'>";
94 echo "<td>Technika: </td> <td><input type='text' name='_technika' placeholder='Technika'></td>";
95 echo "</tr>";
96 echo "<tr style='background-color:#ccc2ff;'>";
97 echo "<td>Druh: </td> <td><select name='technika'>
98 <option value='0'>pozemnÃ</option>
99 <option value='1'>vzdušná</option>
100 </select>
101 </td>";
102 echo "</tr>";
103 echo "<tr align='center' style='background-color:#ccc2ff;'><td colspan='2'> <input type='submit' name='pridat' value='Pridat'></td></tr>";
104 echo "</table>";
105 echo "</form>";
106}
107?>
108</body>
109</html>