Prova così.

Codice PHP:
<?php
session_start
();
if (isset(
$_POST['posted']))
{
    
// username password
    
$username=$_POST['username'];
    
$password=$_POST['password'];

    
// MySQL injection
    
$username trim($username);
    
$password trim($password);

    
$username stripslashes($username);
    
$password stripslashes($password);

    
$username mysql_real_escape_string($username);
    
$password mysql_real_escape_string($password);

    
$result=mysql_query("SELECT COUNT(*) FROM utentisito WHERE username='$username' and password='$password'");

    
// verifica rilsutato
    
$count=mysql_result($result0);
    if(
$count==1)
    {
        
// creazione sessioni e pagina riservata
        
$_SESSION['username']=$username;
        
$_SESSION['password']=$password;
        
header("location:mainpage.php");
        exit;
    }
    else
    {
        echo 
"Username o password sono sbagliati. Riprova.";
    }
}
?>