Skip to content
Advertisement

isset vs empty vs is_null

I’m trying to write a script that when a user uploads a file and does not enter a name an error is returned. I’ve tried using is_null, empty, and isset and they all do not work. Eg, below, is_null returns an error even when a name is entered. Can anyone help?

JavaScript

Advertisement

Answer

isset() will check if the variable is set, ie

JavaScript

empty() will check if the variable is empty, ie

JavaScript

is_null() will check for NULL which is different from empty, because it’s set to NULL not an empty string. (NULL might be a confusing concept)

Since your title is a string, I think you want to be using empty()

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement