Your problem is this bit:
$input = $vCode
That is not comparing the variables. It’s assigning the value of $vCode
to $input
. If you want to compare the two values, you need to use ==
or ===
.
$input == $vCode
It still wouldn’t work though, because you haven’t actually defined $input
. You’re only defining it after the comparison, which isn’t much use.
So your logic needs to look like this:
$vCode = 11111;
$message="";
if( ! isset( $_POST['submitbutton'] ) ) {
$message="not submitted";
} else {
$input = $_POST['vCode'];
if ( $input == $vCode ) {
$message="Success! You entered: " . $input;
} elseif ( $input != $vCode ) {
$message="OOps";
}
}
Note that:
- We’re assigning
$_POST['vCode']
to$input
before checking it. - We’re not bothering to check if
$_POST['submitbutton']
is set, because the only reason that code would be running is if it was, because of the first condition. - We’re using
==
to compare the value. We’re using==
and not===
, because$vCode
is an integer, while$_POST['vCode']
will be a string. If you’re actually getting$vCode
from post meta, then it will also be a string, in which case you can use===
.
Regarding that last point, the best solution would be to convert them both to integers and use a strict comparison:
if ( (int) $input === (int) $vCode ) {