Go Back   CodingForums.com > :: Server side development > PHP > Post a PHP snippet

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-15-2011, 03:30 PM   PM User | #1
myfayt
Senior Coder

 
Join Date: Apr 2010
Posts: 1,159
Thanks: 46
Thanked 96 Times in 95 Posts
myfayt can only hope to improve
Checking Input Number Values

A common mistake when dealing with POST values of forms is not checking for all areas of problems. Here is a few to remember. I hope this is helpful.

When dealing with numbers only

PHP Code:
if (isset($_POST['submit'])) {
$idnumber $_POST['idnumber'];

if (!
is_numeric($idnumber)) {
echo 
'Error! this does not contain only numbers, please do not use letters or symbols.';
}

if (
$idnumber 0) {
echo 
'Error! You cannot use negative numbers.';
}

if (
strlen($idnumber) > 4) {
echo 
'Error, you can only use 4 numbers.';
}

if (
$idnumber == 0) {
echo 
'Zero is not a number, please change it to a number.';
}

if (
$idnumber == EMPTY) {
echo 
'The field is blank, please go back and type in a value';

myfayt is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:33 AM.


Advertisement
Log in to turn off these ads.