loading...

PHP Login Issue

silentcoderr profile image silentCoderr ・1 min read

Please i designed a login page which displays some text when password and username are correct and also displays text when both not correct, but after clicking the login button it keeps saying incorrect password even when i put in the correct password, assistance needed urgently please

<?php;
$host="localhost";
$user="root";
$password="";
$db="login";

$conn=mysqli_connect($host,$user,"$password");
mysqli_select_db($conn, 'loginform');

if (isset($_POST['submit'])) {
    $uname=$_POST['username'];
    $password=$_POST['password'];

    $sql="SELECT * from loginform where User='".$uname."'AND Pass='".$password."'limit 1";

    $result=mysqli_query($conn, $sql);

    if($result==1){
        echo "You have successfully been logged in";
        exit();
    }
    else {
        echo "You have Entered an incorrect password";
        exit();
    }
}
?>
Enter fullscreen mode Exit fullscreen mode

Please your urgent assistance is highly appreciated

Discussion

pic
Editor guide
Collapse
silentcoderr profile image
silentCoderr Author

I've seen the bug,the result was supposed to be "not equal to 1" as opposed to the ==1 I used earlier ... This way $result !=1
Probably coz I'm using php7.1 coz I see the ==1 works fine with other people

Collapse
hasi94 profile image
Hasitha Charaka Gangoda

change your mysql to this

$sql = "SELECT id FROM loginform WHERE User = '$uname' and Pass = '$password' LIMIT 1";

Collapse
silentcoderr profile image
silentCoderr Author

still no change yet

Collapse
manishfoodtechs profile image
manish srivastava

Look at this : tutorialrepublic.com/php-tutorial/...

change variables as per yours.

A good programmer should choose oop or pdo over mysqli.

Thread Thread
silentcoderr profile image
silentCoderr Author

So I have to discard everything and start all over! Oh No!! Thanks anyways
Though if there's still any corrective assistance on the mysql, it'll be appreciated

Collapse
manishfoodtechs profile image
manish srivastava

submit button name is username?
if (isset($_POST['username']))

Collapse
silentcoderr profile image
silentCoderr Author

Oh Yeah! that's true... But I've updated it in the code, still the same, no changes!
Pls give further assistance