SQLインジェクションの間違った対策かと思いきや全然違ったでござる。

htmlspecialcharsは表示する直前で行う
DBに入れるときはSQLインジェクション対策として、mysql_real_escape_string等を使う

参考
PHP: SQLインジェクション - Manual
http://www.php.net/manual/ja/security.database.sql-injection.php