Ah, I think I missed where you said that the function put quotes around the string. You'd have top get more fancy in that case. Like use comments, or escaped characters maybe.
You still need to strip out other special characters, though. Just replacing the quote character isn't enough. & % # ' ; are all dangerous, off the top of my head.
BTW: Why are you trying to do this by hand? Just about every language has built in sanitizing functions already. And they do then in a different (and better) way. Rather than trying to find and replace "bad characters" in the input string, you should be just escaping every character.
So if someone entered a username as
a' OR '1=1';--
then that exact string would get entered as their username into the database. No mangling of the input which restricts user input and causes usability problems. (Especially with password fields, where you WANT there to be special characters)