-3

i need to confirm login using Php and mysql. My codes keep bringing 'username and password not correct even when it is. Please where did i get it wrong.

HTML code looks like this

enter image description here

PHP code looks like this

enter image description here

Thank you

4 Answers4

1

issue 1 : $user_name = $_POST['username']; you have used single quotes wrongly . Same for password in the screen shot. https://i.stack.imgur.com/FlUyR.jpg

issue 2 : mysqli_query($CONNECTIONHANDLER, $QUERY) but you are missing connectionhandler.

Full Code changes :

$username = mysqli_real_escape_string($con,$_POST['username']);

$password = mysqli_real_escape_string($con,$_POST['pass_word']);


$rs = mysqli_query($con, "Select username, pass_word from verify where username = '%s' and pass_word = '%s'", $username, $upassword);

$check_user = mysqli_num_rows($rs);

if($check_user>0){
    echo "Logged in / valid user ";
} else {
    echo "username / password incorrect";
}
Senthil
  • 2,156
  • 1
  • 14
  • 19
0

change '$_POST[username]' to $_POST['username'] and same goes for password.

You are actually assigned string values instead of getting them from $_POST array

Danyal Sandeelo
  • 12,196
  • 10
  • 47
  • 78
0

Remove simple quote

$username = $_POST['username'];
$password = $_POST['pass_word'];

Keep in mind that POST input should ALWAYS be sanitized to avoid injection

rak007
  • 973
  • 12
  • 26
0

I think you are doing it wrong. Also you just posted your username and password on the internet. The query is redundant. You should just check for the presence of a user with such username and password (for example Select Count(*) from...) the second control you are doing is superfluous. Also you are declaring a variable inside a while and you are trying to access those values from outside of it.

Also there are some syntactic errors like quotes and stuff that other users already suggested.

Luca Angioloni
  • 2,243
  • 2
  • 19
  • 28