What kind of errors? Please read How (Not) To Ask A Question. It will help us be able to help you better.
Also is there any reason you are tied to this script? Others have suggested it and I will reiterate, have you looked at nms? I hate to say this to you but I am not going to spend much more time trying to help you with this script as I feel it is bad and insecure code. If you decide to use nms or write your own I would be more than welcome to help you but, you first need to read How (Not) To Ask A Question and do what it suggests. You started out with too little information and you didn't include any errors... not a good thing to do. Do some reading and then come back enlightened.