I
I
Igor Unknown2014-12-27 23:01:02
PHP
Igor Unknown, 2014-12-27 23:01:02

Why doesn't PHP + MySql authorization work?

<?php
include 'config/bd.php';

if (isset($_POST['submit'])) 
{
    if (empty($_POST['login'])) 
    {
        $info_input = 'Вы не ввели логин';
    }
    elseif (empty($_POST['password'])) 
    {
        $info_input = 'Вы не ввели пароль';
    }
    else 
    {    
        $login = $login;
        $password = $password;            
        $user = mysqli_query($connection, "SELECT `id` FROM `user` WHERE `login` = '$login' AND `password` = '$password'");
        $id_user = mysqli_fetch_array($user);
                
        if (empty($id_user['id'])) 
        {
            $info_input = 'Введенные данные не верны';
        }
        else 
        {
            $_SESSION['password'] = $password; 
            $_SESSION['login'] = $login; 
            $_SESSION['id'] = $id_user['id']; 

            $info_input = 'Вы успешно вощли в систему';         
        }     
    }
}
        
$info_input = isset($info_input) ? $info_input : NULL;
echo $info_input;
?>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
E
Eugene, 2014-12-27
@JB_Defalt

$login = $login;
$password = $password;

change to
$login = $_POST["login"];
$password = $_POST["password"];

Don't forget about input processing to protect your site from hacking.

F
FanatPHP, 2014-12-27
@FanatPHP

$login = $login;
$password = $password;

What do these two lines do?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question