I can't get my PHP 'if' working as I want, this is the code I use
if ($loginselect = $mysqli->query("SELECT something FROM options WHERE type='anything'")) {
$loginselect1 = mysqli_fetch_assoc($loginselect);
$loginselect2 = $loginselect1['something'];
echo $loginselect2;
if ($loginselect2 = '1') {
?>
<h1>Title1</h1><hr>Text1
</div>
<?php
}
else {
?>
<h1>Title2</h1><hr>Text2
</div>
<?php
}
}
I echo the value $loginselect2 as you can see and it says 0, but it still echoes text 1 and not text 2. Is this an isue with PHP or am I doing something wrong?
When comparing a variable with a value, you use ==
(or ===
if strict), not =
.
So in your case, you want if ($loginselect2 == '1') {
.
You need two == signs for your if statement.
if ($loginselect2 == '1') {
?><h1>Title1</h1><hr>Text1
</div>
<?php
}
else
{
?>
<h1>Title2</h1><hr>Text2
</div>
<?php
}
}