no... you should return at the end:
function insert($table, $fld, $val)
{
$query = "INSERT INTO $table (%s) VALUES (%s)";
$query = sprintf($query, implode(",", $fld), implode(",", $val));
$result = mssql_query($query) or die;
....
$ret_result=mssql_query("SELECT @@IDENTITY");
return mssql_result($ret_result,0,0);
}
and be careful not to close the connection before that