Your validate function only exists inside the block that starts at the line:
if(isset($_POST['uname']) && isset($_POST['password']))
but you are trying to call it from outside of the block. So move it outside of that block so it is accessible from other parts of the code, something like:
function validate($data)
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
return $data;
}
$uname = '';
$pass = '';
if(isset($_POST['uname']) && isset($_POST['password']))
{
$uname = validate($_POST['uname']);
$pass = validate($_POST['password']);
}
You should read up on the subject of "scope of variables and functions in PHP".