Solved

HTML forms to MySQL

Posted on 2012-03-29
2
339 Views
Last Modified: 2012-03-29
Dear Experts,

Could I ask a very general, on web pages there can be seen forms where for example a text field can have even 1000 characters long.

Technically when these data are submitted to a MySQL table, basically this all 1000 characters are going to one single field? Or there is some other solution as the length of the fields is limited maybe in MySQL?

thanks,
0
Comment
Question by:csehz
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 31

Accepted Solution

by:
Marco Gasi earned 500 total points
ID: 37781746
You can use something like this (found in php.net manual: http://php.net/manual/en/function.substr-replace.php)

<?php
function str_replacer($_string, $_length, $_replacer = ' ...'){
    // Remove any HTML tags present in the string
    $_string = strip_tags($_string);
    if(strlen($_string) > $_length){
        // Find the position for last white space after the string has been shortened to our desired length
        // This helps us to shorten the string without chopping the character or word from the middle
        // ASCII value for the white space is 32
        $_last_white_space_pos = strripos(substr($_string, 0, $_length), 32);
        return substr_replace($_string, $_replacer, $_last_white_space_pos);
    }
    else{
        return $_string;
    }
}
?>

// How to call
<?php
  if (strlen($_POST['text']) > 500) str_replacer($_POST['text'], 500)

 ?>

This function has the advantage to not truncate words

Cheers
0
 
LVL 1

Author Closing Comment

by:csehz
ID: 37782612
Thanks
0

Featured Post

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
In this series, we will discuss common questions received as a database Solutions Engineer at Percona. In this role, we speak with a wide array of MySQL and MongoDB users responsible for both extremely large and complex environments to smaller singl…
The viewer will learn how to count occurrences of each item in an array.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question