Combobox with Mysql

Asked

Viewed 171 times

0

I am not able to take the data from the unit table and put it in a combobox. The combobox does not work and appears to subanswer. I have a table called "tblutentes" with the name of the user and then I have a table called unit with the names of the units. Wanted a combobox that received the name of the drive that is saved in mysql.

here I have 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 combobox part:

 <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>

As it is currently appearing: inserir a descrição da imagem aqui

1 answer

0

Make sure you are not forgetting to close some html tags. And it also seems that the first select (within the form "unit") is not within one with some class "col", so this may be causing the problem with the overlap. If you are using the bootstrap grid system, it is also important to use the "Rows".

Grid System: https://getbootstrap.com/docs/4.0/layout/grid/

It is also recommended not to use "form" within "form", ends up not working well and having some unforeseen behaviors.

  • Thank you so much for the help, I’m using materialize

  • @If I’m not mistaken, the materialize also uses a system similar to "Rows" and "cols" (https://materializecss.com/grid.html). You still got the problem?

  • thanks a lot for the help, but really as it was giving so much trouble I gave up doing this way

Browser other questions tagged

You are not signed in. Login or sign up in order to post.