Bugfixes and anti-sginjection fix

Credits to Ivo P from http://www.phphulp.nl/ for the anti sqlinjection
method of the ' fix the last fix wasn't safe against sqlinjection
apparently
Also fixed some other things