I can not get the data from the unit table and put it in a combobox. The combobox does not work and appears overwritten. I have a table named "tblutentes" with the user name and then I have a table called unit with the unit names. I wanted a combobox that received the name of the drive that is stored in mysql.
Here is the introductory code:
<?php
session_start();
error_reporting(0);
include('includes/config.php');
if(strlen($_SESSION['alogin'])==0)
{
header('location:index.php');
}
else{
if(isset($_POST['add']))
{
$nomeutente=$_POST['NomeUtente'];
$sql="INSERT INTO tblutentes(NomeUtente) VALUES(:nomeutente)";
$query = $dbh->prepare($sql);
$query->bindParam(':nomeutente',$nomeutente,PDO::PARAM_STR);
$lastInsertId = $dbh->lastInsertId();
$query->execute();
if($lastInsertId)
{
$msg="Utente Adicionado Com Sucesso!";
}
else
{
$error="Erro, tente novamente!";
}}
?>
And here's the part of making the combobox:
<div class="row">
<form class="col s12" method="POST">
<div class="input-field">
<?php if($error){?><div class="errorWrap"><strong>ERROR</strong>:<?php echo htmlentities($error); ?> </div><?php }
else if($msg){?><div class="succWrap"><strong>SUCESSO</strong>:<?php echo htmlentities($msg); ?> </div><?php }?>
<form name="unidade" method="POST" action="">
<label for="">Selecione a unidade</label>
<select>
<option>Selecione...</option>
<?php while($prod = mysql_fetch_array($query)) { ?>
<option value="<?php echo $prod['UniID'] ?>"><?php echo $prod['TipoUnidade'] ?></option>
<?php } ?>
</select>
</form>
<div class="input-field col s6">
<i class="material-icons prefix">account_circle</i>
<input id = "NomeUtente" type = "text" class = "validate" name = "NomeUtente" required>
<label for="nomeutente" class="active">Nome Utente</label>
</div>
<button class="btn #ff7043 deep-orange lighten-1 right" type="submit" name="add">Adicionar
<i class="material-icons right">send</i>
</button>
</div>
</form>
</div>