1
I have a form with a dropdown
, that should have as options users registered in a table of my database.
The connection:
<?php
$connection = mysqli_connect("localhost", "root", "", "db_formacao");
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
?>
The form:
<!-- Content -->
<?php
require 'conn.php';
$query = mysqli_query("SELECT NOME FROM colaboradores");
?>
<div class="container">
<div class="row">
<div class="col-lg-12 text-center">
<h1 style="
margin-top:100px;">Inscrição</h1>
<p> </p>
<p class="lead"></p>
<ul class="list-unstyled">
<form id="cadastro" method="post" action="banco/updateP.php" style="
text-align: left;
margin-top:50px;">
<div class="col-lg-12">
<div class="form-group" style="
text-align: left;">
<label for="FORMACAO">Formação: </label>
<input type="text" required class="form-control" id="FORMACAO" name="FORMACAO" value="<?=$row['nome']?>">
</div>
</div>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="TURMA">Turma: </label>
<input type="text" required class="form-control" id="TURMA" name="TURMA">
</div>
</div>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="COLABORADOR">Colaborador: </label>
<select class="form-control" id="COLABORADOR" name="COLABORADOR">
<option>Selecione...</option>
<?php while($colab = mysql_fetch_array($query)) { ?>
<option value="<?php echo $colab['NOME']; ?>"><?php echo $colab['NOME']; ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-lg-12">
<div class="form-group" method="post" style="
text-align: left;">
<label for="PREVISTO">Status: </label>
<input type="text" required class="form-control" id="PREVISTO" name="PREVISTO" value="Previsto">
</div>
<div class="form-check form-check-inline disabled">
<label class="form-check-label">
<input class="form-check-input" type="radio" name="STATUS" id="STATUS" value="Realizado" disabled> Realizado
</label>
</div>
<div class="">
<button type="submit" class="btn btn-primary btn-lg btn-block">Salvar</button>
</div>
</div>
</form>
</ul>
</div>
</div>
</div>
Options simply do not appear. Someone can point me to the error?
Hello @Marianaferreira. First, you are using an extension that was discontinued - mysql*.
– Godfrey the King
Second point, how the table is modeled collaborators? It has a column in Capslock calling for NAME?
– Godfrey the King
The variable you should print would be $Prod and not $colab (which apparently does not exist)
– Inácio Régis
Thank you for answering, Godfrey! First point: I use an old version of php and can’t update, so Mysqli doesn’t work so well for me. Second point: Yes, my table has a column in caps called NAME. Third point: I changed the while variable to $colab, but it still doesn’t work.
– Mariana Bayonetta
@Marianaferreira I posted a reply before checking that your last comment. I strongly advise on you if possible update to mysqli. If impossible, in my answer, use the extension mysql*.
– Godfrey the King
@Marianaferreira Tell me something... You commented that the extension mysqli does not work so well for you... But it is available from version 5 up to PHP. Which version are you using? There’s really no sense in you using the extension mysql*.
– Godfrey the King
I use version 5.2.10. It is impossible to upgrade because many systems run in this version and most of it I don’t even have access to.
– Mariana Bayonetta
I’ll try to use mysqli
– Mariana Bayonetta
Is this application in a production environment? If so, then use mysql* same. If you are in production and the extension does not work, maybe you should compile the PHP with a flag indicating the mysqli... So, I repeat, if you’re in production continue with the mysql.
– Godfrey the King
Mari, take a look at my edition. Just replace your select with the one I put.
– Godfrey the King
If you are using the above code as it is published, you pairedmysqli_ with mysql. Vela $Connection = mysqli_connect.... E in the while($colab = mysql_fetch_array form
– user60252