1

When passing parameters to the login function in the authenticate class i get these errors:

Notice: Undefined index: user in C:\Users\Adam\PhpstormProjects\website\login.php on line 11 Notice: Undefined index: pass in C:\Users\Adam\PhpstormProjects\website\login.php on line 12

this is my function in the authenticate class

 public function login($user,$pass){}

and this is the login.php where the params are getting passed from.

 $authenticateUser = new authenticate();
 $queryResult = $authenticateUser->login(($email),($password));

does anybody understand why i am getting these errors?

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
  • 1
    It appears that the password you provided to the function was undefined. Print out the password before it is sent to the login function to verify it for correctness. – Mr. Polywhirl Dec 05 '14 at 23:19
  • The error means that the index `pass` (e.g. `$array['pass']`) does not exist. If you do not know if an index exists then you should always check, before using it. – Sverri M. Olsen Dec 05 '14 at 23:24
  • @Mr.Polywhirl I've changed it so its passing the post variables $queryResult = $authenticateUser->login($_POST['user'],$_POST['pass']); but im still getting the same errors, my phtml includes text fields with name="user" and another with name="pass" –  Dec 05 '14 at 23:28
  • @SverriM.Olsen thanks for your comment, i understand i have to check isset before passing –  Dec 05 '14 at 23:31
  • Show us line 11 and line 12 where the error arise. – Mohammed Joraid Dec 06 '14 at 00:18

2 Answers2

0

Try this to ensure you are passing the variables:

if ((isset($_POST['user'])) and (isset($_POST['pass']))) {
   $queryResult = $authenticateUser->login($_POST['user'],$_POST['pass']); 
}
JuanSedano
  • 1,025
  • 8
  • 14
0

Check your HTML form that has the input fields to make sure you are having the correct tags names.

<input type="text" name= "user" value=""/>
<input type="text" name= "pass" value=""/>

And make sure you are passing POST as in method="POST" not GET.

Then print your $_POST and $_GET the first thing on your PHP page and then exit() to check if you are actually getting the input.

print_r($_POST);
print_r($_GET);
die("Done...");

Then you must validate your POST array to see if the user is actually typing something in form and not submitting it empty. I guess you already have a validation class that you can use with your framework, if not, then at least validate plainly.

if(isset($_POST["user"]) && !empty($_POST["user"]) && strlen($_POST["user"])>1)
{

//do your stuff
}
 else
{
//show error
}
Mohammed Joraid
  • 6,202
  • 2
  • 27
  • 38