Jump to content

[SOLVED] how to insert fix character length


TheJuan

Recommended Posts

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
Share on other sites

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
Share on other sites

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
Share on other sites

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
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.