TheJuan Posted July 17, 2009 Share Posted July 17, 2009 hi im wondering if PHP is capable of inserting fix character length in mysql field, and how it be possible or could point me to a article/tutorial related to this. sample. i have a textbox > Firstname: Glenn Lastname: Mission after i submit this data, mysql store this to fld_firstname, fld_lastname as 15 varchar length adding a blank space to the rightside to make it a 15 characters in total i have done forum search and web search but with no luck. more power Quote Link to comment Share on other sites More sharing options...
teng84 Posted July 17, 2009 Share Posted July 17, 2009 have you tried using trim? Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted July 17, 2009 Share Posted July 17, 2009 str_pad but you don't have to fill it in with spaces to submit it, it's 15 characters max, not 15 character exactly. Quote Link to comment Share on other sites More sharing options...
phporcaffeine Posted July 17, 2009 Share Posted July 17, 2009 In the form element: maxlength='15' In the post-back code: $_POST['MY-15-CHAR-FEILD'] = trim($_POST['MY-15-CHAR-FEILD']); AND/OR (this method is a bit more aggressive but the trade off is that it will always be 15 chars) $_POST['MY-15-CHAR-FEILD'] = substr($_POST['MY-15-CHAR-FEILD'], 0, 14); Quote Link to comment Share on other sites More sharing options...
TheJuan Posted July 17, 2009 Author Share Posted July 17, 2009 thanks for the reply i thought trim() removes all whitespace characters from both the left and right ends of a string. what i would like to make is to add a whitespace to a variable firstname, lastname that could make it a 15charachter data field stored in mysql. greatly appreciated Quote Link to comment Share on other sites More sharing options...
genericnumber1 Posted July 17, 2009 Share Posted July 17, 2009 thanks for the reply i thought trim() removes all whitespace characters from both the left and right ends of a string. what i would like to make is to add a whitespace to a variable firstname, lastname that could make it a 15charachter data field stored in mysql. any help Read my post. Quote Link to comment Share on other sites More sharing options...
TheJuan Posted July 17, 2009 Author Share Posted July 17, 2009 Read my post. thank you 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.