if($_POST['user_admin'] = 0){ $acct_type = "a standard"; }
elseif($_POST['user_admin'] = 1){ $acct_type = "an administrator"; }
echo $acct_type;
echo $_POST['user_admin'];
Whether $_POST['user_admin']
is 0 or 1, $acct_type
still returns "an administrator" Why?
You need to use "==" when comparing variables.
if($_POST['user_admin'] == 0){ $acct_type = "a standard"; }
elseif($_POST['user_admin'] == 1){ $acct_type = "an administrator"; }
echo $acct_type;
echo $_POST['user_admin'];
It should be
if $variable == 0
you are assigning value with = you should use $variable == 0 to compare the value
You are on the first of 10 common PHP mistakes to avoid :-)
$_POST['user_admin'] = 0
$_POST['user_admin'] = 1
are both assignments. PHP evaluates whether the final assigned expression is true or false after assigning the value to $_POST['user_admin'] . So, the first one will evaluate to false since the assigned value is 0, and the second one will evaluate to true since the assigned value is 1.
As everyone pointed out, you have to use "==" instead of "=" for conditional statements.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With