Jump to content

Varchar Lengths


LunarIsSexy

Recommended Posts

I always thought Varchar's were what controlled the maximum amount of characters or data that could be stored in that structure. I was wondering what I should set the Varchar to for something like a Bio.

 

400 characters minimum.

 

I might be wrong about it, but I hope I'm not because I have it set to 1024 right now and whenever I update my bio if it is really long like over 50 characters it won't save.

Link to comment
Share on other sites

The length given to varchar does set the maximum byte length of what the field will store. How many characters this correlates to would depend on the charset in use but for plain English text usually it is about the same.

 

As for what value you should use for a bio field, that depends on how long you want to allow a persons bio to be. If you want to allow someone to write a several page BIO about themselves then you'd probably want to use a TEXT type rather than varchar. If you want to keep the bio's short with just a few paragraphs then probably a 1000 length would be plenty.

 

Either way you need to include a length check in your code so that if they exceed the allowed length they will get an error. Depending on what settings your mysql server is running with trying to insert a longer than allowed value may either cause an error or just silently truncate the value.

Link to comment
Share on other sites

The length given to varchar does set the maximum byte length of what the field will store. How many characters this correlates to would depend on the charset in use but for plain English text usually it is about the same.

 

As for what value you should use for a bio field, that depends on how long you want to allow a persons bio to be. If you want to allow someone to write a several page BIO about themselves then you'd probably want to use a TEXT type rather than varchar. If you want to keep the bio's short with just a few paragraphs then probably a 1000 length would be plenty.

 

Either way you need to include a length check in your code so that if they exceed the allowed length they will get an error. Depending on what settings your mysql server is running with trying to insert a longer than allowed value may either cause an error or just silently truncate the value.

 

I have the Varchar set to 1024, thats it. I can save about 50 letters worth of text and if I go over it won't save at all. How would I go about making to so max is 400 chars?

Link to comment
Share on other sites

Whatever is causing your issue of not being able to save 50 characters is likely not an issue with your field definition, but rather your code processing the data.

 

Are you sure that you are only using 50 characters? Add debugging logic to your code so you can see exactly how long the string you are inserting is and also verify the SQL query you generate is valid.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.