A few things:

1. To get rid of the undefined index try using isset, so in your case

if((!isset($_POST['username']) && empty($_POST["Username"])) || (!isset($_POST['password']) &&...