0
Hello, I’m making an editing page, and in it I have an input type="radio"
, and I’m not getting the radio flagged according to the value in the database...
I’m trying to pull this way, but it doesn’t work, is always marked what has the value "F"
, even though M at the bank...
<?php
$sql = mysqli_query($con, "SELECT * FROM pacientes WHERE sus = '$sus' ");
while ($cont = mysqli_fetch_array($sql)) { ?>
<div class="col">
<label class="col-form-label">Sexo</label><p>
<input type="radio" name="sexo" id="sexo" value="M" <?php if ($sexo = 'M') {echo ' checked ';} ?> />Masculino</label>
<input type="radio" name="sexo" id="sexo" value="F" <?php if ($sexo = 'F') {echo ' checked ';} ?> />Feminino</label>
</div>
<?php } ?>
Where am I going wrong?
You are assigning the value M to the variable $sex, to compare use two equal signs (==)
– user60252
=
defines a value ;==
compare without typing ;===
compares with typing– Papa Charlie