One further small point: make sure you enclose always enclose values in the mysql query string in single quotes (even if you expect an integer - form forgers might have other ideas) ie:
INSERT INTO table SET column='$var'
Oops just realised Laserlight said that already. Time I went to bed.