Sorry for the long post but:
I've never used functions previously (created them) and I still haven't looked at any formal reading for creating and using your functions, but I have looked at other samples for code... and here are the two I have:
function connect() {
if ($dbc = @mysql_connect ('localhost', 'root', 'password')) {
if (!@mysql_select_db ('barwarenew')) {
die ('Could not connect to database, please contact the administrator');
}
} else {
die ('Could not connect to database, please contact the administrator');
}
}
function login() {
$username = $_POST['username'];
$password = md5($_POST['password']);
$loginquery = "SELECT * FROM users WHERE username = '$username' AND password = '$password' LIMIT 1";
$loginresult = mysql_query($loginquery) or die(mysql_error());
if($row = mysql_fetch_array($loginresult)) {
$_SESSION['logged'] = "Yes";
$_SESSION['id'] = $row['userid'];
$_SESSION['username'] = $row['username'];
$_SESSION['password'] = $row['password'];
$_SESSION['email'] = $row['email'];
$_SESSION['realname'] = $row['realname'];
$_SESSION['usertype'] = $row['usertype'];
} else {
return false;
}
}
And here's the HTML...
<?php
if (isset($_POST['login'])) {
connect();
login();
} else {
?>
<div class="contentbox">
<div class="contentboxtop">
<div class="contentboxtoptext">
Log In
</div>
</div>
<div class="contentboxbottom">
<div class="contentboxbottomtext">
<div class="contentboxbottomtext">
<form name="login" method='post' action='' enctype='multipart/form-data'>
Username
<br />
<input type="text" name="username" size="16">
<br />
Password
<br />
<input type="password" name="password" size="16">
<br />
<br />
<input type='submit' name='login' value='Submit'>
</form>
</div>
</div>
</div>
</div>
<?php
}
?>
Sorry for such long code but I'm stuck. Now, what I want to do is this but I have no idea how (using functions)...
1. If the function is returned flase (something bad occurs, such as wrong password) it shows the login box again, but with an error that says "Please Try Again" right above the form. (See picture at bottom, where orange line is)
2. If it returns true, I want to redisplay the box, except with SOME TEXT instead of the form, depending on $_SESSION['UserType']; (completely get rid of the form and replace it with text)
3. Change the words Log In, to User Panel
I know how to do all this with PHP If statements, but I never used functions before so...
(I also need to check BEFORE the form is displayed, if the session is active, and only display the form if it isnt)
I know it's kind of confusing, but ask me questions if you dont get what im trying to say... and here's a picture:

I really appreciate ANY help I can get, I've been lurking for a while and have always found a thread related to what I needed except now and everyone has always been such a great help, so thanks.