-
Notifications
You must be signed in to change notification settings - Fork 0
/
registracija.php
162 lines (148 loc) · 5.19 KB
/
registracija.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<?php session_start(); ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
<link rel="stylesheet" href="style.css">
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Roboto:wght@300;400;500;700;900&display=swap" rel="stylesheet">
<link rel="shortcut icon" type="image/ico" href="img/favicon.ico"/>
<title>REGISTRACIJA</title>
<style>
.main {
height: 620px;
padding-top: 50px;
}
input {
width: 96%;
height: 25px;
padding: 3px 4px 3px 10px;
margin-bottom: 0px;
box-shadow: rgba(255, 255, 255, 0.2) 0px 0px 0px 1px inset, rgba(0, 0, 0, 0.9) 0px 0px 0px 1px;
border: none;
border-radius: 3px;
}
.bojaPoruke {
color: #EA212D;
position: absolute;
text-align: center;
margin-top: -8px;
}
.mes {
margin-top: -18px;
}
.pass_mes {
margin-top: 15px;
}
.showpass {
width: 15px;
height: 15px;
margin: 15px 3px 0 8px;
padding: 0;
position: relative;
box-shadow: none;
}
.main p {
position: absolute;
top: 740px;
left: 38%;
font-size: 18px;
font-weight: bold;
}
@media (max-width: 600px) {
.main p {
top: 920px;
left: 25%;
}
}
</style>
</head>
<body>
<div class="logo">
<a href="index.php"><img src="img/logo.svg" /></a>
</div>
<div class="nav">
<div class="wrapper">
<a href="index.php">HOME</a>
<a href="kategorija.php?kategorija=svijet">SVIJET</a>
<a href="kategorija.php?kategorija=ekonomija">EKONOMIJA</a>
<a class="foc" href="registracija.php">REGISTRACIJA</a>
<a href="login.php">PRIJAVA</a>
</div>
</div>
<div class="main">
<div class="wrapper">
<div class="log">
<h2>REGISTRACIJA</h2>
<form enctype="multipart/form-data" method="POST" action="">
<input name="ime" id="ime" type="text" class="ime" placeholder="Ime" required/>
<br/><span id="porukaIme" class="bojaPoruke"></span>
<br/><br/>
<input name="prezime" id="prezime" type="text" class="ime" placeholder="Prezime" required/>
<br/><span id="porukaPrezime" class="bojaPoruke"></span>
<br/><br/>
<input name="username" id="username" type="text" class="username" placeholder="Korisničko ime" required/>
<br/><span id="porukaUsername" class="bojaPoruke"></span>
<br/><br/>
<input name="pass" id="lozinka" type="password" class="pass" placeholder="Lozinka" required/>
<br/><input type="checkbox" class="showpass" onclick="myFunction1()">Prikaži lozinku
<br/><span id="porukaPass" class="bojaPoruke mes"></span>
<br/>
<input name="pass" id="lozinkaRep" type="password" class="pass pass_mes" placeholder="Lozinka" required/>
<br/><input type="checkbox" class="showpass" onclick="myFunction2()">Prikaži lozinku
<br/><span id="porukaPassRep" class="bojaPoruke mes"></span>
<br/>
<input name="submit" type="submit" class="prijava" id="prijava" value="Registracija" />
</form></div>
<?php
$servername = "localhost";
$username = "root";
$password = "";
$basename = "sadrzaj";
$dbc = mysqli_connect($servername, $username, $password, $basename) or
die('Error connecting to MySQL server.'.mysqli_connect_error());
if ($dbc && isset($_POST['submit'])) {
$ime = $_POST['ime'];
$prezime = $_POST['prezime'];
$username = $_POST['username'];
$lozinka = $_POST['pass'];
$hashed_password = password_hash($lozinka, CRYPT_BLOWFISH);
$razina = 0;
$registriranKorisnik = false;
$sql = "SELECT * FROM korisnik WHERE korisnicko_ime = ?";
$stmt = mysqli_stmt_init($dbc);
if (mysqli_stmt_prepare($stmt, $sql)) {
mysqli_stmt_bind_param($stmt, 's', $username);
mysqli_stmt_execute($stmt);
mysqli_stmt_store_result($stmt);
}
if (mysqli_stmt_num_rows($stmt) > 0) {
echo "<p style='color:#EA212D;font-weight:bold'>Korisničko ime već postoji!</p>";
} else {
$sql = "INSERT INTO korisnik (ime, prezime,korisnicko_ime, lozinka, razina) VALUES (?, ?, ?, ?, ?)";
$stmt = mysqli_stmt_init($dbc);
if (mysqli_stmt_prepare($stmt, $sql)) {
mysqli_stmt_bind_param($stmt, 'ssssd', $ime, $prezime, $username, $hashed_password, $razina);
mysqli_stmt_execute($stmt);
$registriranKorisnik = true;
}
}
if($registriranKorisnik == true) {
echo '<p>Korisnik je uspješno registriran!</p>';
}
}
mysqli_close($dbc);
?>
</div>
</div>
<footer>
<div class="wrapper">
<br/><p>Projektni zadatak iz kolegija <i>Programiranje Web Aplikacija</i></p>
<br/><p>Autor projekta: <b>Mario Vidović</b><br/>mvidovic@tvz.hr</p>
<br/><p>Godina izrade: 2021.</p>
</div>
</footer>
<script src="reg.js"></script>
</body>
</html>