开发者

error checking to ensure that a field isn't blank?

My website has an opt-in member directory. Currently, the error checking function simply looks at the form $_POST to see if (!empty($userRealName)) and then allows the member to appear in the list.

It took about 30 minutes for someone to show up as a blank name in the list, and upon examination of the database I've determined it's because their "real name" is - in other words, a single space.

So, clearly that blows right through my simple !empty() check. W开发者_如何学JAVAhere do I go from here to enforce users needing a name to be listed in the directory?


Use trim to remove blank characters in the beginning and end of the string. Also try to enforce which characters are allowed in the field, for example with preg_match or filter_var.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜