For example, the nickname of the user in the mysql table field is stored as varchar. The length of the varchar, as I recall, 255 bytes.
Do I need to check that the length of the nickname is more than 255 characters (we will assume that the size of each symbol is 1 byte) and output to the user a message that "the length of the nickname is more than 255 characters"?
Or not to pay for the length of attention and keep the field in the database, and error (by the way, mysql will give an error if you try to record more data than possible?) prompt you with a message that "could not complete your request"?
If I should check whether it is necessary to do it generally for every text field? For example, the size of the field of type bigtext?
Of course it is necessary to do for the user , if there is "could Not complete your request", he will think that the site is outside , but if "allowed nick length is more than 255 characters" then it will be that much clearer!
Cade_Bradt answered on July 4th 19 at 22:58
> by the way, mysql will give an error if you try to write more data than can?
No, mysql will not give an error (from JhaoDa UPD: if you turned off strict mode (STRICT_TRANS_TABLES)). He simply cut the string to the desired length, in your case, up to 255 characters.
So the answer is Yes, check the length of the string you need to do, or simply if you exceed 255 characters, you lose the data.
summer_Ankunding answered on July 4th 19 at 23:00
JS check what the user enters, will be much nicer handling errors, but in php I would also check made.