LunarIsSexy Posted September 20, 2013 Share Posted September 20, 2013 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. Quote Link to comment Share on other sites More sharing options...
kicken Posted September 20, 2013 Share Posted September 20, 2013 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. Quote Link to comment Share on other sites More sharing options...
LunarIsSexy Posted September 20, 2013 Author Share Posted September 20, 2013 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? Quote Link to comment Share on other sites More sharing options...
kicken Posted September 20, 2013 Share Posted September 20, 2013 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. Quote Link to comment Share on other sites More sharing options...
vinny42 Posted September 21, 2013 Share Posted September 21, 2013 "I have the Varchar set to 1024, thats it. I can save about 50 letters worth of text" Which version of MySQL are you using, and that happens when you say "it doens't save"? Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.