I want to prevent an empty value from going into a MySQL database
I’m using following but for some reason it is letting the empty values get through…
if (trim($var)= '' || !isset($var)){
header("Location:page.php?er=novariablel");
}
else {
...insert into database
}
Note, there is a bunch of complicated stuff that sets the value of var which is why I want to have both the ='' and the !isset because either might be the case.
Am I missing something with the or statement, i.e. it evaluates to false if both are true. Or what am I doing wrong?
Try:
empty()is a better way to check to see if a variable has no value. Just keep in mind that the following will return true:The following things are considered to be empty: