First.. theres lots of errors in your markup(missing </td>, extra </form> etc.). Theres no need to print large chunks of html markup with php(you printed the form with php for some reason).
Do all the checking at the start of your script(before any markup). Separate logic and presentation. That means that you should put errors to string(or array) and you just print the errors later in the markup if they exist. Heres a rough example:
<?php
session_start();
require("../functions/checkEntries.php");
include_once "../DBconMOD.php";
include_once "../style_sheet.php";
// Check that username and passwd is submitted
if (isset($_POST['username']) AND isset($_POST['passwd']))
{
$error = array(); // Initialize error variable
if (empty($_POST['username']))
{
$error[] = 'Please input username';
}
if (empty($_POST['passwd']))
{
$error[] = 'Please input password';
}
if (count($error) == 0)
{
$sql = sprintf("SELECT * FROM admin_coach WHERE userName = '%s' AND userPass = '%s' LIMIT 1",
mysql_real_escape_string($_POST['username']),
mysql_real_escape_string($_POST['passwd'])
);
$result = mysql_query($sql);
if (mysql_num_rows($result) == 1)
{
$info = mysql_fetch_assoc($result);
$_SESSION['idAdmin'] = $info['idAdmin'];
$_SESSION['accessLvL'] = $info['accessLvl'];
$_SESSION['nameF'] = $info['nameF'];
$_SESSION['nameL'] = $info['nameL'];
// Session is set and login was succesfull, redirect the user to somewhere
header("Location: header_test.php");
exit();
}
else
{
$error[] = 'Your user name or password are not valid';
}
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Language" content="en-us" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<link rel="stylesheet" type="text/css" href="../../templates/master_style_sheet.css" />
</head>
<body>
<img src="../artwork/CupLogo.png" width="265" height="94" /><hr />
<?php if (!empty($error)): ?>
<p class="error">
<?php implode('<br />',$error) ?>
</p>
<?php endif; ?>
<form action="userlogin_coach.php" method="post">
<label>Username</label>
<input name="username" type="text" />
<label>Password</label>
<input name="passwd" type="password" />
<br />
<input type="submit" name="submit" value="Login" />
</form>
</body>
</html>
BTW, dont save your password as cleartext but only a hash(and compare that when checking if the user and pass is correct).
Bottomline is. Dont do any complex logic inside your html portion. Do as much as you can and set things to variables, objects etc. in the logic portion of your code.