Go Back   CodingForums.com > :: Server side development > PHP

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 02-18-2010, 05:39 PM   PM User | #1
Nightchild
New Coder

 
Join Date: Jun 2007
Location: Canada
Posts: 49
Thanks: 1
Thanked 1 Time in 1 Post
Nightchild is an unknown quantity at this point
String length check failing

Afternoon Everyone

I am having trouble validating the length of a variable returned from a form. The value received from the form appears to be correct, the results from strlen is within the required range but this check fails if the received input is numbers. If the input received from the form is alphanumeric, the function works correctly.

What am I missing?

Code:
PHP Code:
if (isset($_POST['devid'])) {
    
$Device->device_id stripString($_POST['devid'], 'device_id');
    if (
strlen($Device->device_id) < || strlen($Device->device_id 20)) {
        
$user_msg "<li>Device ID is not valid ($Device->device_id). len=".strlen($Device->device_id)."</li>";
    }
} else { 
Output echoed to screen when it failed:

Device ID is not valid (0002310). len=7

The value of "0002310" is 100% correct. As you can see from the output line, post stripping it has maintained the leading zeroes and is 7 characters long - which should not fail the length check.

I have tried within the $Device object, to define the variable as string using:
PHP Code:
$this->device_id    = (string) $row->device_id
to try to force it to work as a string.

Thanks.
Alan
__________________
Of all the things I've lost in my life time, my mind is the one I miss the most!
Nightchild is offline   Reply With Quote
Old 02-18-2010, 05:57 PM   PM User | #2
JAY6390
Regular Coder

 
Join Date: Dec 2009
Location: UK
Posts: 495
Thanks: 0
Thanked 58 Times in 58 Posts
JAY6390 is on a distinguished road
change
PHP Code:
if (strlen($Device->device_id) < || strlen($Device->device_id 20)) { 
to
PHP Code:
if (strlen($Device->device_id) < || strlen($Device->device_id) > 20) { 
The > 20 needs to be outside of the strlen function
__________________
My site: JayGilford.com
Resources:
PHP Pagination Class | Getting all page links | Handling PHP Errors properly
If you like a users help, show your appreciation with the rep and thanks buttons :)
JAY6390 is offline   Reply With Quote
Users who have thanked JAY6390 for this post:
Nightchild (02-18-2010)
Old 02-18-2010, 06:35 PM   PM User | #3
Nightchild
New Coder

 
Join Date: Jun 2007
Location: Canada
Posts: 49
Thanks: 1
Thanked 1 Time in 1 Post
Nightchild is an unknown quantity at this point
Resolved

Thank you!

I had a feeling it was one of those id10t type errors.
__________________
Of all the things I've lost in my life time, my mind is the one I miss the most!
Nightchild 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 01:22 AM.


Advertisement
Log in to turn off these ads.