Answer the question
In order to leave comments, you need to log in
How to check whether there are variables at once in one if?
There is such a code. It works but...
if(!isset($_GET['id']))
{
exit('Отсутствует обязательный параметр "ID"');
}
if(!isset($_GET['id'] or $_GET['id2']))
{
exit('Отсутствует обязательный параметр "ID"');
}
Answer the question
In order to leave comments, you need to log in
This is the correct way to check two variables:
if (!isset($_GET['id']) || !isset($_GET['id2'])) {
exit('Отсутствует обязательный параметр "ID"');
}
Enable error reporting and be more careful.
You do this: take the value of $_GET['id']. Does it not exist? Checking id2. There is? So it returns one. We check with isset if a unit exists.
And for you you need:
if (!isset($_GET['id']) && $_GET['id2']) ...
(if both values don't exist). If you want an error to pop up if at least one value does not exist, you need if (!isset($_GET['id']) || $_GET['id2']) ...
Also, !empty is better for your purpose , since for isset "0" is a completely valid value, and for empty it will return false
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question