-
Notifications
You must be signed in to change notification settings - Fork 1
/
tallennakahvio.php
123 lines (101 loc) · 3.2 KB
/
tallennakahvio.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
114
115
116
117
118
119
120
121
122
123
<?php
session_start();
// Define MySQL server credentials
$username = "root";
$password = "password";
$dbname = "kahvio";
// Create connection
$conn = mysqli_connect("db", $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Could not connect to MySQL server: " . mysqli_connect_error());
}
// Check if user has admin privileges
$credentials = $_SESSION["credentials"];
$query = "SELECT admin FROM credentials WHERE username='$credentials'";
$result = mysqli_query($conn, $query);
$row = mysqli_fetch_assoc($result);
$admin = $row["admin"];
// Redirect non-admin users to login page
if (!$admin) {
header("Location: /kirjauduajax.html");
exit;
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<link rel="stylesheet" href="assets/style.css">
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<style>
table {
background-color: white;
}
</style>
</head>
<body>
<header>
<a href="Login_Home.php"><img src="assets/images/2560px-Sodexo_logo.svg.png"
width="10%";
height="auto" /></a>
<h3><a href="Login_Home.php">Home</a>   <a href="Login_Menu.php">Menu</a>   <a href="Login_OpenTime.php">Open time</a>   <a href="Login_AboutUs.php">About us</a>     <a href="forum.php">Forum</a></h3>
</header>
<kuva><img id="coffee1"src="assets/images/coffeeBeans4.jpg" alt="coffeeBeans"></kuva>
<main>
<?php
$username = isset($_POST["username"]) ? $_POST["username"] : "";
$password = isset($_POST["password"]) ? $_POST["password"] : "";
mysqli_report(MYSQLI_REPORT_ALL ^ MYSQLI_REPORT_INDEX);
try{
$yhteys=mysqli_connect("db", "root", "password", "kahvio");
}
catch(Exception $e){
exit;
}
if (!empty($username) && !empty($password)){
$sql="insert into credentials (username, password) values(?, ?)";
//valmistellaan sql-lause
$stmt=mysqli_prepare($yhteys, $sql);
//sijoitetaan muuttujat oikeisiin paikkoihin
mysqli_stmt_bind_param($stmt, 'ss', $username, $password);
//suoritetaan sql-lause
mysqli_stmt_execute($stmt);
$last_id = mysqli_insert_id($yhteys);
header("Location:tallennakahvio.php");
exit;
}
?>
<?php
print "<table border='1'>";
$tulos=mysqli_query($yhteys, "select * from credentials");
while ($rivi=mysqli_fetch_object($tulos)){
if($rivi->admin!=true){
print "<tr><td><p>$rivi->username <td>$rivi->password <td>$rivi->id".
"<td><a href='./poistakahvio.php?poistettava=$rivi->id'>Poista</a></p>".
"<td><a href='./muokkaakahvio.php?muokattava=$rivi->id'>Muokkaa</a></p></tr>";
}}
print "</table>";
//suljetaan tietokantayhteys
mysqli_close($yhteys);
?>
<br>
<br>
</main>
<footer>
<address>
<ul class="list">
<li><b>Sodexo Oy</b></li>
<li>Vankanlähde 9</li>
<li>13100 Hämeenlinna</li>
<li>p. 010 540 7000</li>
<li>[email protected]</li>
<li>[email protected]</li>
<a href='kirjauduulos.php'>Kirjaudu ulos</a>
</ul>
</address>
</footer>
</body>
</html>