Answer the question
In order to leave comments, you need to log in
PHP. How to get value from database column?
Hello. I got one problem here.
With this line I get id by username:
$passwordByID = mysql_query("SELECT password FROM users WHERE id = '".$IdByName."'");
if($password == $passwordByID) {
//все правильно
}
<?php
require 'db_connect.php';
if($_POST['username'] == "")
{
echo("Введите логин.");
} else {
$username = $_POST['username'];
}
if($_POST['password'] == "")
{
echo("Введите пароль.");
} else {
$password = md5($_POST['password']);
}
if(isset($username) && isset($password))
{
$q1 = mysql_query("SELECT * FROM users WHERE username = '".$username."'");
if(mysql_num_rows($q1) == 1) {
$IdByName = mysql_query("SELECT id FROM users WHERE username = '".$username."'");
$passwordByID = mysql_query("SELECT password FROM users WHERE id = '".$IdByName."'");
if($password == $passwordByID)
{
echo "Вы успешно авторизовались.";
} else {
echo "Вы ввели неверный пароль."; }
} else {
echo "Пользователя с таким именем не существует.";
}
}
?>
Answer the question
In order to leave comments, you need to log in
php.net/manual/en/mysqli.query.php
php.net/manual/en/function.password-hash.php
1st mistake: do not store the password in the database as a password, store the hash of the password, user id and secret key for example.
2nd: Mysql gives out not what you want, but what you request, in my opinion there are too many quotes and you are looking for id = line .$IdByName. instead of the value from the variable, as needed.
3rd: Why are you sure that $passwordByID is not the correct result, and not $IdByName or $password? Dump all three variables through var_dump and see what's in them.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question