forked from krupecek/ZSHT-PHP-DB
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
113 lines (111 loc) · 3.31 KB
/
index.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
<?php
/*
Plik wymagany.
Jeśli nie istnieje, wystąpi bład krytyczny.
Serwer przerwie ładowanie strony.
*/
require_once('database.php');
if(isset($_GET['send'])) {
$send = 'a'.$_GET['send'];
switch($send) {
case 'ateacher':
$data = [
'imie' => $_POST['imie'],
'nazwisko' => $_POST['nazwisko'],
'pesel' => $_POST['pesel']
];
$db_conn = dbConnect($db_server, $db_name, $db_user,$db_pass);
$sql = 'insert into nauczyciele values (NULL, :imie, :nazwisko, :pesel)';
$db_stmt = $db_conn->prepare($sql);
$db_stmt->execute($data);
$db_conn = null;
header('Location: index.php');
break;
default:
echo 'Co robisz dzbanie!';
}
}
if(isset($_GET['cmd'])) {
$cmd = 'c'.$_GET['cmd'];
switch($cmd) {
case 'cupdate':
$data = [
'id' => $_GET['id']
];
$db_conn = dbConnect($db_server, $db_name, $db_user,$db_pass);
$sql = 'select imie, nazwisko, pesel from nauczyciele where id = :id';
$db_stmt = $db_conn->prepare($sql);
$db_stmt->execute($data);
$teacher = $db_stmt->fetchAll();
$db_conn = null;
break;
case 'cdelete':
break;
default:
echo 'Co robisz dzbanie!';
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>Document</title>
<style>
.list .title {
font-weight: bold;
padding: 15px;
}
.content div {
display: inline-block;
width: 15%;
padding: 15px;
}
.content:hover {
background-color: #ddd;
}
.content div a {
text-decoration: none;
color: #000;
cursor: default;
border: 1px solid #eee;
border-radius: 5px;
padding: 10px;
margin: 0 5px;
}
.content div a:hover {
background-color: #fcc;
}
</style>
</head>
<body>
<form action="index.php?send=teacher" method="post" name="addTeacher" id="addTeacher">
<input type="text" name="imie" value="<?= (isset($teacher[0]['imie'])) ? ($teacher[0]['imie']) : ('') ?>" id="">
<input type="text" name="nazwisko" value="<?= (isset($teacher[0]['nazwisko'])) ? ($teacher[0]['nazwisko']) : ('') ?>" id="">
<input type="text" name="pesel" value="<?= (isset($teacher[0]['pesel'])) ? ($teacher[0]['pesel']) : ('') ?>" id="">
<input type="submit" value="Zapisz">
</form>
<div class="list" id="nauczyciele">
<div class="title">Nauczyciele</div>
<?php
$db_conn = dbConnect($db_server, $db_name, $db_user,$db_pass);
$db_query = $db_conn->query('select * from nauczyciele');
foreach($db_query as $row) {
?>
<div class="content">
<div><?= $row['imie'] ?></div>
<div><?= $row['nazwisko'] ?></div>
<div><?= $row['pesel'] ?></div>
<div>
<a href="index.php?cmd=update&id=<?= $row['id'] ?>">Edytuj</a>
<a href="index.php?cmd=delete&id=<?= $row['id'] ?>">Usuń</a>
</div>
</div>
<?php
}
?>
</div>
</body>
</html>