-4

Hi all i'm currently studying php and I don't understand whats wrong with my if else statement :( I keep on getting the wrong variable about put even though my declared string if different.Could anyone give me an idea where im going wrong. Cheers.

$password = strlen('username');


if($password = strlen('password')){
    echo 'password is valid';
}
else if ($password = strlen('username')){
    echo 'password is invalid';
}

I keep on getting the output 'password is valid'

  • 2
    To compare, you use `==`, not `=`, which assigns the value instead. – Nick Oct 15 '18 at 11:12
  • 'username' and 'password' both have 8 characters, to strlen will always be true. – Gavin Simpson Oct 15 '18 at 11:13
  • In addition to the above points, I think than you don't actually understand what `strlen` is supposed to do. It tell you the length of the string. – Ben Hillier Oct 15 '18 at 11:51
  • And my 2nd point: What are you actually trying to do here? Take two strings, one containing the literal `password`, and one containing the literal `username`, and make some coding decision based on it. No user input data is being processed at all. – Ben Hillier Oct 15 '18 at 11:53

1 Answers1

0

Both the strlen are equal and so the IF condition satisfies here and that causes the problem throwing 'password is valid'

Reference: http://php.net/manual/en/function.strlen.php

Hariharan V.
  • 191
  • 1
  • 3
  • 18