I am building a form and am currently working through validating the input.
basically what I want to do is check that they entered something, if so escape it and add it to a variable, otherwise add an error to the potential list of errors to be displayed later.
I currently have:
$category = isset($_POST['category']) ? mysqli_real_escape_string($DBConnect, $_POST['category']) : $error[] = "Which Category is this request for?";
when I do a var_dump on $category (when entered) I get NULL, when not entered I get STRING(35) “Which Category is this request for?”
I have also tried changing the line to read:
isset($_POST['category']) ? $category = mysqli_real_escape_string($DBConnect, $_POST['category']) : $error[] = "Which Category is this request for?";
but var_dump still says it is NULL.
Could someone explain to me what I am doing wrong?
cheers,
issetwill only check whether that variable is set or not NULL.If you want to check for blank also Then please use
emptyThis will return you thetruein following cases.The following things are considered to be empty: