You don't really need a function. You want to put your form inside the body tag, not the head tag. Also, if you use single quotes your echo statements will echo the variable names rather than the variable values. I prefer heredoc syntax to echo blocks of code, but that is just a personal preference.
I am assuming you are running PHP 4.1 or higher and the opening html and body tags are higher up in your script.
<?php
If ($_POST['submit'] {
if($_POST['password'] == "123" && $_POST['username'] == "abc"){
$action = "a";
$character = "Nilesh";
$plan_num = "1";
} else if $_POST['password'] == "Dr" & $_POST['username'] == "Wi"){
$action = "b";
$character = "Will";
$plan_num = "2";
} else if $_POST['password'] == "Da" & $_POST['username'] == "Ar"){
$action = "c";
$character = "Avishkar";
$plan_num = "3";
} else {
$loginfailed = "<strong>Log-In Incorrect! </strong><br>username or password. <br>";
}
If ($loginfailed) {
echo "$loginfailed";
} else {
echo <<<END
<form name="form1" method="post" action="link$action.php">
<input name="submit" type="submit" id="submit" value="Enter $character >>">
<input name="upplanpass" type="hidden" id="upplanpass" value="plan$plan_num">
</form>
END;
}
echo "</body></html>";
exit;
}
?>
Your other form looks fine.