Help combobox php

0

Good night, I have an urgent question here, I have tried several solutions and I can not understand

I intend to populate a combobox from a database, then I want to select a value and delete it.

<html>          
    <form action="presidente_apaga_utilizadores.php" method="post">
            Selecione o ID a apagar: 
                <select name="nome">
                    <option value="option"></option>
    </form>
                        <?php
                            require("basedados.h");
                            $sql="SELECT nome FROM utilizador where tipo_utilizador !=1";
                            $result = mysqli_query($conexao, $sql);
                            while($row = mysqli_fetch_array($result)){
                                $nome = $row["nome"];;
                                echo '<option value="' . $nome .'">' . $nome . '</option>';
                            }   
                                if ($_POST(["nome"])) {
                                $sql = "DELETE FROM utilizador WHERE nome = '$nome'";
                                $resultado = mysql_query($sql);
                                    echo " Registo Apagado!<p>";
                                }

                        ?>

                </select>
            <input type="submit" value="Submit"><br>

    
asked by anonymous 05.05.2016 / 23:29

1 answer

1
<html>
<?php
  require("basedados.h");

  if ($_POST(["nome"])) {
    $sql = "DELETE FROM utilizador WHERE nome = '$nome'";
    $resultado = mysql_query($sql);
    echo " Registo Apagado!<p>"; }
?>      
    <form action="presidente_apaga_utilizadores.php" method="post">
      Selecione o ID a apagar: 
      <select name="nome">
      <option value="option"></option>
      <?php
          $sql="SELECT nome FROM utilizador where tipo_utilizador !=1";
          $result = mysqli_query($conexao, $sql);
          while($row = mysqli_fetch_array($result)){
          $nome = $row["nome"];
          echo '<option value="' . $nome .'">' . $nome . '</option>';
          }   
          ?>

                </select>
            <input type="submit" value="Submit">
</form>

There are some things to improve on your code, but the answer only answers what you asked.

    
05.05.2016 / 23:50