if this is your code, I doubt it can work at all. you are assigning some text (the sql statement) to a variable, but you don't execute it before calling mysql_insert_id. (I guess your are doing mysql_query sometimes later, else I wouldn't know how your insert statement could be successful 😉)
it should look something like this:
$sql = "INSERT INTO table(field1,field2) VALUES ('$field1','$field2')";
mysql_query($sql);
$id = mysql_insert_id();