I'm creating a login website using PHP.
$valid = true;
$sql = "SELECT name FROM users WHERE username='$username' and password='$password'";
$result = $conn->query($sql);
if ($result === false) {
$valid = false;
}
if ($valid === false) {
echo "Wrong username and password";
}
If I input the wrong username and password, I'll receive the error line. However, when I try to refresh the page, that error line still remains. How can I make it disappear?
CodePudding user response:
I think you have to check if NOT valid.
if ($valid != 1) {
echo "Wrong username and password";
}
CodePudding user response:
$valid = 1;
$sql = "SELECT name FROM users WHERE username='$username' and password='$password'";
$result = $conn->query($sql);
if ($result) {
$valid = 0;
}
if ($valid) {
echo "Wrong username and password";
}