Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts

    filter blank field in db

    hi im running a filter for a varchar field in my db and i have sqeezed the value thru the following

    if !empty

    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 ?

  • #2
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    !empty() will cover all three:
    PHP Code:
    if(!empty($inputVar))
    {
        
    // 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_* functions if you aren't expecting spaces.
    Last edited by Inigoesdr; 12-17-2010 at 08:10 PM.

  • #3
    Senior Coder
    Join Date
    Nov 2010
    Posts
    1,381
    Thanks
    264
    Thanked 32 Times in 31 Posts
    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..

  • #4
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,642
    Thanks
    2
    Thanked 405 Times in 397 Posts
    If there is a space then none of those 3 are going to prevent it. Run your string through trim() or test to make sure it's a valid email.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •