I'm doing a php/ajax login, so the page redirect is in javascript (ajax).
I can already redirect it ajax way (w/o connecting to db, etc.),
but when I add the db, and session stuff in php, i got this php error.

![Notice: Undefined index: username in D:\wamp\www\bday_app\login.php on line 22](https://i.stack.imgur.com/cVFwR.png)

Here's my code:
I got index.php (which has the login form, and the ajax code),
The ajax code uses login.php (using POST method) to pass the username/password.
Here's the content of my login.php:

```
if(mysql_num_rows($query_results)==1){
    $row = mysql_fetch_array($query_results);
    $_SESSION['username'] = $row['username'];
    $_SESSION['nickname'] = $row['nickname'];
    $_SESSION['firstname'] = $row['first_name'];
    $_SESSION['middlename'] = $row['middle_name'];
    $_SESSION['lastname'] = $row['last_name'];
    echo 'Login successful! Redirecting...';
    //header("Location: bday_app_home.php");
}else{
    echo 'Invalid username/ password.';
    //header("Location: index.php");
}

```

Line 22 in the error is:

```
$_SESSION['username'] = $row['username'];

```

If I had an invalid username/password, its fine, coz it will display the message fine in index.php,
but when the username/password is correct, I got this undefined index error.

I don't know why, because username/password was recieved via POST, see the echoed values in the image - mars1, mars123

Please help... :(

Thanks.