0

I have a input text box maxlength 20 and use jquery auto count how many words left.

I have also use strlen to check before it insert into DB varchar(20)(if too many characters, wont insert into DB), and htmlentities to prevent xss

Here is the problem, htmlentities will increase characters. So if auto count shows 17 but it actually over than 17 characters because htmlentities.

I don't want data truncate, any suggestion?

user2178521
  • 833
  • 1
  • 14
  • 26

1 Answers1

6

Never encode for display before storage, only before display.

Ignacio Vazquez-Abrams
  • 776,304
  • 153
  • 1,341
  • 1,358