i have a field in my registration form that contains for instance a name
field,it will be stored in database in a field called user_name varchar(20)
. it's clear that i should validate the user input
if i validate this field frist with code below:
<?php
if(emptiy($_pos['name']) || strlen($_post['name'])>20)
//send an not valid input error
else{
$name=htmlspcialchars($_post['name']);
//check for sql injection;
//insert name into database;}
?>
if a user insert a name like <i> some one </i>
the string length is 17 so the else part will performe and name will be <i> some one </i>
which the length is 28 that will produce an error while inserting to db.in this time if i send an error to user that his/her input is too longe he will got confused. what should i do? what is the best approach?