View Full Version : filter blank field in db
12-17-2010, 08:54 PM
hi im running a filter for a varchar field in my db and i have sqeezed the value thru the following
if != ""
if strlen != 0
question is, puting the varChar field thru all three of those, is there any way a blank field (no user input) can make it thru that barrier..
im having an issue with a blank field passing as having value ... so i wanted to squeez it (its prob overkill i know, but i have to make sure)
did i cover every possible scenario here ?
12-17-2010, 09:06 PM
!empty() (http://php.net/types.comparisons) will cover all three:
// add to db
To be absolutely sure about user input you should cast it to the value you're expecting, and validate it if it's a string. You can check for only [\w\s] characters for instance, or use the ctype_* (http://php.net/ref.ctype) functions if you aren't expecting spaces.
12-17-2010, 09:21 PM
thanks i had the if !empty in there first and for some reason its trying to send an email to blank and i get a mail failure error because there is no address in the sms field. so i added the other two filters to shut it down if it was blank, if i understand !empty correctly a space in the field would pass thru that filter because a space is actually true.
it seems to work now that i put the other two filters in there as well, ill see what happens, i know i shouldnt have to but lets see what happens..
basically the process is when a user sends another use an internal email, it checks to see if the receiver has sms info in that sms field, if so it notifies them, if not, then it should just pass it up and shoot the email to their account as normal..
with just the !empty filter its sending both, the internal mail and the sms to no address (if its blank) thats why i added the other two filters to shut it down if no value..
thanks ill see what happens here... appreciate it..
12-18-2010, 09:30 AM
If there is a space then none of those 3 are going to prevent it. Run your string through trim() (http://php.net/trim) or test to make sure it's a valid email.
Powered by vBulletin® Version 4.2.2 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.