1
I’m trying to use the variable SESSION to pass values to fields, as was used in "login", where if there is something inside the variable, it will be shown in the field, but if it does not exist, nothing will be shown. How can I do the same in select?
<div class="form-group">
<label for="nome" class="col-sm-2 control-label">Login</label>
<div class="col-sm-10">
<input type="text" class="form-control" name="login" placeholder="Login" value="<?php echo $_SESSION['login_consultar']; unset($_SESSION['login_consultar']);?>">
</div>
</div>
<div class="form-group">
<label for="nivel_acesso" class="col-sm-2 control-label">Nível de Acesso</label>
<div class="col-sm-2">
<select class="form-control" name="nivel_acesso">
<option value="1">Administração</option>
<option value="2">Informática</option>
</select>
</div>
</div>
And as the friend @Felipeduarte answered. It is to do so, but it is not used this way to do it. You must generate this content and pass the value with a variable.
– Willian Coqueiro
And how do I do that? I started using the language recently.
– Lucas Ramos
How are you defining this
$_session
? Where the value comes from?– Willian Coqueiro
I’m using it this way: $_SESSION['nivel_acesso_consultar'] = $result['nivel_acesso']; - Onde $resultado é uma mysqli_fetch_assoc of a mysql query
– Lucas Ramos
Why are you moving to a Session? Why not go straight? Ta in another file the query?
– Willian Coqueiro
Yes, it’s in another file.
– Lucas Ramos
Make a
include
in the middle of that file. Before displaying this form, you do the include.– Willian Coqueiro
Exercise a lot in language. Whenever you see a new function and do not know it, you learn about it. After that start programming on top of Frameworks. It will become easier.
– Willian Coqueiro
I’ll do it. Thank you!
– Lucas Ramos