-3

As the title states, I'm unable to match variable $user with variable $_POST['username'].

I've tried echoing the two variables, their outcome is exactly the same.

if ($user==$_POST["username"] ) {
echo"Sucessfully logged in as ".$user;
}
else{
echo'Unable to log you in!';
}

Not much more to say, really.

Remi Guan
  • 21,506
  • 17
  • 64
  • 87
  • not enough code here. check for errors - *"Not much more to say, really."* - same here. – Funk Forty Niner Dec 11 '15 at 20:45
  • 3
    basic debugging: `var_dump($user, $_POST['username']);`. check what you are dealing with. – Marc B Dec 11 '15 at 20:45
  • possible duplicate of http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-index – Funk Forty Niner Dec 11 '15 at 20:46
  • That's about as in-depth as it gets. There's no more code that will help with the situation (I assume) $user is obtained by using fgets() once on a file with all of the userdata. No errors, either. – Alex Groves Dec 11 '15 at 20:47
  • 1
    well, try all those "Try this" answers below. Edit: one down. – Funk Forty Niner Dec 11 '15 at 20:48
  • 1
    if $user is coming from a file it's probably got a \n or \r\n on the end that you're not seeing when you echo them – Rob G Dec 11 '15 at 21:02
  • 1
    @RobGudgeon That's what I was thinking earlier, but OP didn't respond to Marc's comment, nor did they want to share the rest of their *relevant* code, nor any other information relevant to what their results were. There were a few answers who nailed it (one of which deleted; probably because they noticed they basically had the same answer). Marc's comment was indeed a good insight to see what the OP's results would be, and that in its own right, is worth its weight in gold ;-) – Funk Forty Niner Dec 11 '15 at 21:47

1 Answers1

2

Try triming the strings :

if (trim($user) == trim($_POST["username"]) )
Jafar Akhondali
  • 1,552
  • 1
  • 11
  • 25