Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- session_start(); //starting session
- $error = ''; //variable to store error message
- if (isset($_POST['submit'])) {
- if (empty($_POST['username']) || empty($_POST['password'])) {
- $error = "Nick i Hasło nie mogą być puste!"; //error empty pwd and nick
- }
- else {
- $username = $_POST['username']; //define username
- $password = $_POST['password']; //define password
- //connect with database
- $conn = mysqli_connect("localhost", "00194748_otako", "090909B1", "00194748_otako");
- //matching password and username with database
- $query = "SELECT username, password FROM login WHERE username=? AND password=? LIMIT 1";
- //security
- $stmt = $conn -> prepare($query);
- $stmt -> bind_param("ss", $username, $password);
- $stmt -> execute();
- $stmt -> bind_result($username, $password);
- $stmt -> store_result();
- if ($stmt -> fetch()) {
- $_SESSION['login_user'] = $username; //session initializing
- header("location: profile.php"); //rediecting to profile page
- }
- else {
- $error = "Nick lub/i Hasło jest/są niepoprawne/niepoprawny";
- }
- mysqli_close($conn); //closing connection
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement