Sorry for being rude, then.
What you'll want to do for making the variables required is check that they've been set, basically. On the register page, you have your form acting on itself, so in register.php somewhere, you check for the POST information, right? if ($POST['submit']) or something? Well, you want to do:
if (empty($_POST['username']) || empty($_POST['password'])) {
That says 'if either the username or the password are empty' - you'd put your error message or whatever there, and then in the matching else statement, you'd do your SQL call. After successfully running your SQL, you could redirect them. As far as automatically logging them in, I'm not sure if you've worked with sessions or not, but that'd be the way to go with that. A _simple_ example would be something like this:
register.php
<?PHP
// here, we check if the form has been submitted, because we need to handle
// redirection before we handle outputting the HTML stuff.
if (empty($_POST['username']) || empty($_POST['password'])) {
// here, they have not filled in either the username OR the password. Set an error.
$error = 'Please fill in all form fields.';
}
else {
// here, both fields are filled in.
// run your SQL stuff
if ($sqlSuccess) {
// redirect them to the login page, because we successfully ran the SQL
// notice how we haven't output ANYTHING to the browser yet- header() works
header('Location: login.php');
exit();
}
else {
$error = 'There was a problem. That username is taken.';
}
}
// now here, we've either redirected to the login page, this is the first visit, or there
// was an error with the form/registration. So, we echo the HTML
?>
html stuff here - up til the form
<?PHP
// then we check for the error message
if (isset($error)) {
echo $error . '<br />';
}
?>
here we finish our html and output the form
That doesn't touch on automatically logging them in, but it should hopefully illustrate at least a little bit as to how to make the variables required and redirect properly.