-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmuokkaakahvio.php
114 lines (100 loc) · 3.29 KB
/
muokkaakahvio.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
<?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">
<meta name="description" content="Cafe menu page.">
<title>Menu</title>
</head>
<body>
<header>
<a href="Login_Home.html"><img src="assets/images/2560px-Sodexo_logo.svg.png" width="130" height="44" alt="SodexoLogo" /></a>
<h3><a href="Login_Home.html">Home</a>   <a href="Login_Menu.html">Menu</a>   <a href="Login_OpenTime.html">Open time</a>   <a href="Login_AboutUs.html">About us</a></h3>
</header>
<kuva><img src="assets/images/coffeeBeans4.jpg" alt="coffeeBeans"></kuva>
<main>
<?php
$muokattava=isset($_GET["muokattava"]) ? $_GET["muokattava"] : "";
//Jos tietoa ei ole annettu, palataan listaukseen
if (empty($muokattava)){
header("Location:./tervetuloaAdmin.php");
exit;
}
mysqli_report(MYSQLI_REPORT_ALL ^ MYSQLI_REPORT_INDEX);
try{
$yhteys=mysqli_connect("db", "root", "password", "kahvio");
}
catch(Exception $e){
exit;
}
$sql="select * from credentials where id=?";
$stmt=mysqli_prepare($yhteys, $sql);
//Sijoitetaan muuttuja sql-lauseeseen
mysqli_stmt_bind_param($stmt, 'i', $muokattava);
//Suoritetaan sql-lause
mysqli_stmt_execute($stmt);
//Koska luetaan prepared statementilla, tulos haetaan
//metodilla mysqli_stmt_get_result($stmt);
$tulos=mysqli_stmt_get_result($stmt);
if (!$rivi=mysqli_fetch_object($tulos)){
exit;
}
?>
<!-- Lomake tavallisena html-koodina php tagien ulkopuolella -->
<!-- Lomake sisältää php-osuuksia, joilla tulostetaan syötekenttiin luetun tietueen tiedot -->
<!-- id-kenttä on readonly, koska sitä ei ole tarkoitus muuttaa -->
<form action='./paivitakahvio.php' method='post'>
id:<input type='text' name='id' value='<?php print $rivi->id;?>' readonly><br>
Username:<input type='text' name='username' value='<?php print $rivi->username;?>'><br>
Password:<input type='text' name='password' value='<?php print $rivi->password;?>'><br>
<input type='submit' name='ok' value='ok'><br>
</form>
<!-- loppuun uusi php-osuus -->
<?php
//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>