The problem is that it is always displayed. You did not enter the password or login correctly. Why?

Login = 1234567890

Porol = sabedr, which is hashed in sha1. Looks like a cell sha1 (sabedr)

<?php session_start(); require_once('select_db.php'); $login = $_POST['login']; $password = $_POST['password']; $login = '"' . mysql_real_escape_string($login) . '"'; $password = '"' . sha1($password) . '"'; $row_login = 'SELECT login, type FROM datacenter WHERE login=' . $login . ' AND password =' . $password; $row_login = mysql_fetch_assoc(mysql_query($row_login)); if($row_login){ switch ( $row_login['type'] ){ case 'teacher': echo '<script>location.replace("accaunt_teacher.php");</script>'; exit; break; case 'parent': echo '<script>location.replace("accaunt_parent.php");</script>'; exit; break; case 'scholar': echo '<script>location.replace("accaunt_scholar.php");</script>'; exit; break; default: echo 'Не выбран тип'; } } else { echo 'Вы не правильно ввели пароль или логин' . '</br>'; echo $login . '</br>'; echo sha1($password); } ?> 

    2 answers 2

    Why the data never comes I don’t know, but the logic after the limp is lame on both legs, rewrite something like this:

     // так-же надо выбирать не только `login` но и `type`, т.е. $row_login = 'SELECT login, type FROM datacenter WHERE login=' . $login . ' AND password =' . $password; $row_login = mysql_fetch_assoc(mysql_query($row_login)); // делаем выборку и ложим в массив if($row_login) { //если выборка вернула данные switch($row_login['type']) { // тут код... } } else { // вы ввели неправильный логин или пароль } 

    Otherwise, I personally do not see any mistakes ...

    • here correct? I still write wrong login - Zow
    • It means that the correct login or password is not ... Yes, and I did not write that this amendment solves the sample verification problem Make an echo request, see what kind of request you are doing, execute, make sure that the correct password or username is not correct, make the necessary edits (what tells me that this is editing passwords in the database) and enjoy the result ... - Zowie
    • I will clarify the question - what is in the database in the password field? If - sabedr and lies, then I will kill you to her god xD - Zowie
    • so top it is written yes - Zow
    • Login = 1234567890 Porol = sabedr, which is hashed in sha1. - Zow

    You select only login by request, and in switch you try to check the type field

    • However, if the main error were in this, the output would be no DB , or in general the error ala undefined index ... - Zowie
    • and what’s the point of no db, it pulls the login from the table of fields, the request is executed, the login to the variable goes. But the condition he checks is already $ row_login ['type'], and there is no given element in the array, again because only login is pulled. Those. there is only $ row_login ['login'] == 1234567890 and there is nothing else there - DemoS
    • Or I’m hard-guessing, or there’s no data array at all in the code ... Or rather it only appears in if'e, then we try to go through $ row_login ['type'] then when it’s a row ... So I’m not exactly understand what you mean, correct if you snub and apazoritsya somewhere ... - Zowie
    • Well, so mysql_fetch_assoc returns an associative array, the keys of which are the names of the database fields, right? Right. From the database by the query that SELECT login FOM... is selected. At least it was. Therefore, mysql_fetch_assoc cannot return an array with the key type . Now there is SELECT login, type FROM... Now, if the result of the query returns, then in the $ row_login array at least there will be a type key - DemoS
    • I agree, but firstly - the data is not collected at all into an array, secondly - if the problem were this, we certainly would not see Вы не правильно ввели пароль или логин correctly ... I described the pop-up on this part below, in the rest seems to me a problem in the database itself, or in passwords - Zowie