Jump to content

isset function does not work

- - - - -

  • Please log in to reply
3 replies to this topic

#1
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
Hi, i use this code to check if both fields of form are filled in:

   if (!isset($_POST['userName'])){
       echo "Username is not filled in";
       exit();
    } 
    
    if (!isset($_POST['email'])){
       echo "E-mail is not filled in";
       exit();
    } 
However, this code does not print anything when the fields are left empty. No errors are displayed also. Any help, please?

#2
Revolt

Revolt

    Programmer

  • Members
  • PipPipPip
  • 99 posts
According to the manual entry in php for isset, it determines if a variable is set and not null. An empty string "" is not null so it passes that check.

I think what you want is the empty function

#3
thatsme

thatsme

    Programmer

  • Members
  • PipPipPipPip
  • 176 posts
thanks a lot. that works

#4
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
  • Location:Vancouver, Eh! Cleverness: 200
You would benefit from creating your own functions to verify if the email or user name is set, and not empty. I believe there is an is_email or similar function to do this for you, feel free to look in the manual.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users