I think I see where you're going with this, although I don't really see the practical use of it. Try this instead.
switch($_POST['txtUsername']) {
case "user1":
if ($_POST['txtPassword'] == "pass1") include 'index1.php';
else include 'main.php';
break;
case "user2":
if ($_POST['txtPassword'] == "pass2") include 'index2.php';
else include 'main.php';
break;
default:
include 'main.php';
}
Just to explain a little -- It 'switches' on the username entered. If that particular user enters the correct password they see the page you want them to see. Otherwise, they see main.php. Also, if no valid username is entered they also see main.php.
Now let me try to explain what's happening in your code a little.
$username = "user1";
$password = "pass1";
$username = "user2";
$password = "pass2";
// The code above was hopefully just trying to explain the valid users
// and their passwords, because anytime you re-define a variable
// the original value is lost.
if ($_POST['txtUsername'] != user1 && $_POST['txtPassword'] != pass1)
// if a user enters 'bob' as the username and 'pass1' as the password
// this statement evaluates to 'FALSE' and includes index1.php
//-- probably not what you want.
// the first part being TRUE (it's not 'user1') and the second part
// being FALSE (it is 'pass1')
// TRUE && FALSE == FALSE
{
include 'main.php';
}
else
include 'index1.php';
if ($_POST['txtUsername'] != user2 || $_POST['txtPassword'] != pass2)
// Then here we do another evaluation, regardless of the previous test
// and include yet another file.
{
include 'main.php';
}
else
include 'index2.php';