Help combobox php

Asked

Viewed 58 times

0

Good evening, I have here an urgent question, I have tried several solutions and I cannot understand

I intend to popular a combobox from a database, then 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>

  • Dude, you need to fix this html, the form has to finish just after all the controls. And usually the POST treatment is the first thing you do in the code.

  • Man, I know what it’s like when the guy gets scared, but "urgent" is inelegant. It’s here and a community. There’s nobody working for others, you know? I say good, because I’ve been there and I’ve been reprimanded the same way.

  • I’m sorry, if I offended you, I didn’t mean to. I do not want to get the job done, but I am a little exhausted, since yesterday I am trying to solve I have already researched a lot and my last solution was to use the forum.

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 to what you asked.

  • I’m sorry but the code was wrong. Thank you for your attention

  • Man, what was the mistake?

  • Error on IF line

  • Rafael, if you have an error php tells you what the error was. What was the error? I guess because you need to have an isset as well. But even if so, this error should not interfere with the functioning of the rest of the code.

  • gave this error here: Fatal error: Function name must be a string in C: xampp htdocs rafael lpi presidente_apaga_users.php on line 48

  • Missing $connection in $result call? Line 48 is the one you have: $result = mysql_query($sql); ?

  • Another thing, you’re using mysql_query and mysqli_query together?

  • error on this line:

  • if ($_POST(["name"])) { $sql = "DELETE FROM user WHERE name = '$name'"; $result = mysqli_query($sql); echo " Deleted Log! <p>"; }

  • I think I’m just using mysqli_query

Show 5 more comments

Browser other questions tagged

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