· 7 years ago · Dec 04, 2018, 12:12 PM
1<?php
2 $ip = "127.0.0.1";
3 $uzytkownik = "root";
4 $haslo = "admin";
5 $mysqli = new mysqli($ip, $uzytkownik, $haslo, "test");
6 if ($mysqli->connect_errno) {
7 printf("Bład podłączenia z bazą danych: %s\n", $mysqli->connect_error);
8 exit();
9 }
10
11
12 echo '<a href="?akcja=dodaj"><button>Dodaj rekord</button></a>';
13 echo '<a href="index.php"><button>Wyswietl</button></a>';
14
15 if(isset($_GET['akcja'])) {
16 if($_GET['akcja'] == "dodaj") {
17 echo('<h2>Dodawanie</h2>
18<form action="?akcja=dodawanie" method="POST">
19Imie: <input type="text" name="imie"/> Wiek: <input type="number" name="wiek"/> Data: <input type="text" name="data" value="yyyy-mm-dd">
20<input type="submit" value="Dodaj">
21</form>');
22 die();
23 }
24 if($_GET['akcja'] == "dodawanie") {
25 $mysqli->query('INSERT INTO dane(imie, wiek, data) VALUES("'.$_POST["imie"].'","'.$_POST["wiek"].'","'.$_POST["data"].'")');
26 }
27 }
28
29 if(isset($_GET['usun']))
30 $mysqli->query("DELETE FROM zajecia WHERE ID = " . $_GET['usun']);
31
32 $data = $mysqli->query("SELECT * FROM zajecia");
33 echo '<table>';
34 echo '<tr>';
35 echo '<th>Imie</th>';
36 echo '<th>Wiek</th>';
37 echo '<th>Data rejestracji</th>';
38 echo '<th>Usun</th>';
39 echo '</tr>';
40 while($d = $data->fetch_array()){
41 echo "<tr>";
42 echo "<td>".$d[1]."</td>";
43 echo "<td>".$d[2]."</td>";
44 echo "<td>".$d[3]."</td>";
45 echo "<td><a href='index.php?usun=". $d[0] ."'><button>usun</button></a></td>";
46 echo "</tr>";
47 }
48 echo '</table>';
49
50?>
51
52
53
54
55
56
57
58drop table if exists zajecia;
59
60CREATE TABLE IF NOT EXISTS zajecia (
61 ID INT NOT NULL PRIMARY KEY AUTO_INCREMENT,
62 IMIE varchar(14) NOT NULL,
63 WIEK INT NOT NULL,
64 DATA_REJESTRACJI date NOT NULL
65);