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 Link to comment https://forums.phpfreaks.com/topic/166270-solved-how-to-insert-fix-character-length/ Share on other sites More sharing options...
teng84 Posted July 17, 2009 Share Posted July 17, 2009 have you tried using trim? Link to comment https://forums.phpfreaks.com/topic/166270-solved-how-to-insert-fix-character-length/#findComment-876829 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. Link to comment https://forums.phpfreaks.com/topic/166270-solved-how-to-insert-fix-character-length/#findComment-876852 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); Link to comment https://forums.phpfreaks.com/topic/166270-solved-how-to-insert-fix-character-length/#findComment-876857 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 Link to comment https://forums.phpfreaks.com/topic/166270-solved-how-to-insert-fix-character-length/#findComment-876864 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. Link to comment https://forums.phpfreaks.com/topic/166270-solved-how-to-insert-fix-character-length/#findComment-876867 Share on other sites More sharing options...
TheJuan Posted July 17, 2009 Author Share Posted July 17, 2009 Read my post. thank you Link to comment https://forums.phpfreaks.com/topic/166270-solved-how-to-insert-fix-character-length/#findComment-876872 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.