I feel like it should works my logic is correct and no error showing on hosting text editor yet error
Fatal error: Cannot use isset() on the result of an expression (you can use "null !== expression" instead)
showed up
here's the code
if (!isset(htmlentities($_POST['test'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5, "UTF-8")) == "test123") {
echo "ERROR!1<br>";
}
should i first save $_POST['test'] on different variable and htmlentities it or what's the best approach?
CodePudding user response:
The code for what you defined inside the question should look like this
if (isset($_POST['test'])) {
if (htmlentities($_POST['test'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5, "UTF-8") !== "test123") {
echo "ERROR!1<br>";
}
} else {
echo "ERROR!1<br>";
}
I have used 2 if statements on the first section so the line is not that long. If you want, feel free to combine them into a single statement.
On the other hand, do you really need the htmlentities
function? You should check your logic, I am unable to tell based on the question. If not then the code looks like this:
if (!isset($_POST['test']) {
echo "ERROR!1<br>";
} else {
if ($_POST['test'] !== "test123") {
echo "ERROR!1<br>";
}
}
CodePudding user response:
i fixed it ...I just store htmlentities to outside variable and instead of comparing it i negate it i think it much aesthetic
$test = htmlentities($_POST['test'], ENT_QUOTES | ENT_SUBSTITUTE | ENT_HTML5, "UTF-8");
if ($test != "test123") {
echo "ERROR!!<br>";
}