I don't think it is returning the right value here. Try echoing $tid just before you run your sql, or better yet, echo the sql to the screen and check that it has the right variables.
Right mate I think we are almost there!
I checked the table and yes the data is going in but there are problems in the tid and reply_id fields......
in the tid field it has the wrong value which why the error is poping up.....also the value in the tid is the ID of the previous comment to which a reply is being made......
and for the reply_id the value is going in as 0
and yes the mss function is not getting the right value....:S