4 changed files with 104 additions and 0 deletions
@ -0,0 +1,25 @@ |
|||
<?php |
|||
session_start(); |
|||
require("init.php"); |
|||
|
|||
|
|||
$username = $_POST["username"]; |
|||
$pw = $_POST["pw"]; |
|||
|
|||
$sql = "SELECT * FROM nk_users |
|||
WHERE username='$username' AND password='$pw'"; |
|||
$result = mysqli_query($conn, $sql); |
|||
|
|||
if(mysqli_num_rows($result) == 1) { |
|||
$row = mysqli_fetch_assoc($result); |
|||
|
|||
$_SESSION["logged"] = 1; |
|||
$_SESSION["username"] = $row["username"]; |
|||
$_SESSION["role"] = $row["role"]; |
|||
$_SESSION["userid"] = $row["id"]; |
|||
|
|||
header("Location: /"); |
|||
} else { |
|||
header("Location: login.php?error=1"); |
|||
} |
|||
?> |
@ -0,0 +1,30 @@ |
|||
<?php |
|||
session_start(); |
|||
include("init.php"); |
|||
|
|||
$username = $_POST["username"]; |
|||
$pw1 = $_POST["pw1"]; |
|||
$pw2 = $_POST["pw2"]; |
|||
|
|||
if ($pw1 != $pw2) { |
|||
header("Location: reg.php?error=1"); |
|||
} |
|||
|
|||
$sql = "INSERT INTO nk_users(username,password,role) |
|||
VALUES ('$username','$pw1','5')"; |
|||
|
|||
if (mysqli_query($conn,$sql)){ |
|||
$last_id = mysqli_insert_id($conn); |
|||
echo "uživatel byl vytvořen, jeho id: ".$last_id ; |
|||
|
|||
$_SESSION["logged"] = 1; |
|||
$_SESSION["username"] = $username; |
|||
$_SESSION["role"] = "5"; |
|||
$_SESSION["userid"] = $last_id; |
|||
|
|||
header("Location: /"); |
|||
} else { |
|||
echo "error:" . mysqli_error($conn); |
|||
} |
|||
|
|||
?> |
@ -0,0 +1,18 @@ |
|||
<?php |
|||
session_start(); |
|||
include("init.php"); |
|||
|
|||
$title = $_POST["title"]; |
|||
$msg = $_POST["msg"]; |
|||
$userid = $_SESSION["userid"]; |
|||
|
|||
$sql = "INSERT INTO nk_prispevky(id_nk_users,title,msg,created) |
|||
VALUES ('$userid','$title','$msg',now())"; |
|||
|
|||
if(mysqli_query($conn,$sql)){ |
|||
echo "bylo zapsáno do knihy"; |
|||
header("Location: /list.php"); |
|||
} else{ |
|||
echo "error:". mysqli_error($conn); |
|||
} |
|||
?> |
@ -0,0 +1,31 @@ |
|||
<?php |
|||
session_start(); |
|||
include("init.php"); |
|||
|
|||
?> |
|||
<!DOCTYPE html> |
|||
<html lang="en"> |
|||
<head> |
|||
<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>Navštěvní kniha</title> |
|||
</head> |
|||
<body> |
|||
<h1>Návštěvní kniha</h1> |
|||
|
|||
<?php |
|||
include "menu.php"; |
|||
?> |
|||
|
|||
<?php |
|||
if(isset($_SESSION["username"])){ |
|||
echo "<h2> vítej uživateli: ".$_SESSION["username"]."</h2>"; |
|||
} else { |
|||
echo "<h2> Prosím přihlaš se </h2>"; |
|||
} |
|||
|
|||
?> |
|||
|
|||
</body> |
|||
</html> |
Loading…
Reference in new issue