Retrieve an ID and insert into Combobox for changes

Asked

Viewed 275 times

0

What I need to do is recover the id and insert it in the combobox to change the data but the combobox is empty do not know why, if anyone can help me I appreciate.

Recovers Data from Database

<?php
   session_start();
    $ID_Cliente = $_SESSION['ID_Cliente'];


    $conexao = mysql_connect("localhost:3306","root","root") or die("Erro durante a conexão do banco de dados");
    mysql_select_db("prestadora",$conexao);
    mysql_query("SET NAMES 'utf8'", $conexao);
    mysql_query('SET character_set_connection=utf8', $conexao);
    mysql_query('SET character_set_client=utf8', $conexao);
    mysql_query('SET character_set_results=utf8', $conexao);
    $consulta= "select * from pedido where ClienteID_Cliente='$ID_Cliente' " ;
    $resultado=mysql_query($consulta,$conexao) or die ("Não foi possível Consultar os seus dados.");
    mysql_close($conexao);


      while($consulta=mysql_fetch_array($resultado)){

        $Tipo_Servico=$consulta["Tipo_Servico"];
        $DataVisita=$consulta["DataVisita"];
        $HoraVisita=$consulta["HoraVisita"];
        $EnderecoVisita=$consulta["EnderecoVisita"];          
        $ID_Pedido=$consulta["ID_Pedido"];    


      }

?>

Form of the Change

<header id="cabecalho">
    <img src="_imagens/logo.jpg">
</header>
<br class="fixFloat">
<nav id="menu">
    <ul>
        <li><a href="index.html" target="_self">Home</a></li>
        <li><a href="cadastra-se.html" target="_self">Cadastra-se</a></li>
        <li><a href="login.html" target="_self">Login</a></li>
    </ul>
</nav>



<section id="form">
    <fieldset id="form_field">
        <legend id="form_legend">Alterar Pedido</legend>

        <?php
        include "_php/listarpedido.php";
        ?>

              <form method="post" action="_php/alterarpedido.php">
                 Escolher qual alterar<select name="ID_Pedido">
                 <option value="<?php echo $ID_Pedido;?>"></option> </select><br/><br/>
                 Tipo de Serviço: <select name="Tipo_Servico"  value="<?php echo $Tipo_Servico;?>">
                 <option name="Reforma Predial">Reforma Predial</option>
                 <option name="Jardinagem">Jardinagem</option>
                 <option name="Eletricista">Eletricista</option>
                 <option name="Encanador">Encanador</option>
                 </select> 
                 Data de Visita: <input type="text" name="DataVisita" value="<?php echo $DataVisita;?>">  
                 Hora de Visita: <input type="text" name="HoraVisita" value="<?php echo $HoraVisita;?>"><br/><br/>
                 Endereço de Visita: <input type="text" name="EnderecoVisita" value="<?php echo $EnderecoVisita;?>" >
                <fieldset id="form_field">
                      <legend id="form_legend">Alterar</legend>
                      <input type="submit" id="botao" value="Alterar">
                      <input type="reset" id="botao" value="Resetar">
                </fieldset>
            </form>

</section>


</body>
</html>

Change in the Bank

<header id="cabecalho">
    <img src="../_imagens/Logo.jpg">
</header>
<br class="fixFloat">
<nav id="menu">
    <ul>
        <li><a href="../index.html" target="_self">Home</a></li>
        <li><a href="../cadastra-se.html" target="_self">Cadastra-se</a></li>
        <li><a href="../login.html" target="_self">Login</a></li>
    </ul>
</nav>


<section id="form">
    <?php

    $ID_Pedido=$_POST["ID_Pedido"];
    $Tipo_Servico=$_POST["$Tipo_Servico"];
    $DataVisita=$_POST["DataVisita"];
    $HoraVisita=$_POST["HoraVisita"];
    $EnderecoVisita=$_POST["EnderecoVisita"];




    $conexao = mysql_connect("localhost:3306","root","root") or die("Erro durante a conexão do banco de dados");
    mysql_select_db("prestadora",$conexao);
    mysql_query("SET NAMES 'utf8'", $conexao);
    mysql_query('SET character_set_connection=utf8', $conexao);
    mysql_query('SET character_set_client=utf8', $conexao);
    mysql_query('SET character_set_results=utf8', $conexao);
    $atualiza= "update cliente set Tipo_Servico='$Tipo_Servico',DataVisita='$DataVisita',HoraVisita='$HoraVisita',EnderecoVisita='$EnderecoVisita' WHERE ID_Pedido='$ID_Pedido'" ;
    mysql_query($atualiza,$conexao) or die ("Não foi possível executar a atualização.");
    mysql_close($conexao);



    echo"<fieldset id='form_field'><legend id='form_legend'>Dados do Pedido</legend>
  <p>Dados do Pedido Alterados com Sucesso !!!</p></fieldset>";



    ?>
<fieldset id="form_field">
     <legend id="form_legend">Voltar</legend>
    <a href="../menucliente.html" id="botao">Voltar</a>
</fieldset>

</section>


</body>
</html>
  • Where is your doubt exactly, not missing a js there not?

  • in this section "Choose which to change<select name="Id_request"> <option value="<? php echo $Id_request;? >"></option> </select><br/><br/>";

  • it becomes empty the combobox, does not receive the bank id

  • Tmb does not have validations the server is all indormacoes even if it is not post and does the mysql query. Other if you are just updating a system that is already written and has a php less than 5.6 ai all right. If you do not suggest you update your php.

  • It is empty because you did not have anything displayed. Try to see the HTML source printed by the browser. I guarantee that in select the value field is with the id. However, nothing will appear in the form because you have not printed anything. You must have the id or name displayed inside the option tag

  • but ta here <option value="<? php echo $Id_request;? >"></option>

  • Do <option value="<?php echo $ID_Pedido;?>"><?php echo $ID_Pedido;?></option>. Remember that the value of option is not displayed, but what is between the tags.

  • now ta displaying the number 3 which is the third id record but does not display all id registration in the table

  • or rather not displaying the rest,the rest of the table id

  • Ai Voce has to implement another sql with the data and make a loop

  • and would do what to change the other attributes when I change the combobox ID ?

  • Ai tries with ajax or jQuery.

  • has some turtorial or some similar example ??. For me to follow because this then I do not know anything yet, I am in learning process kk

Show 8 more comments

1 answer

0


Now yes. You should have it displayed inside the option tag like this

<option value="<?php echo $id;?>"><?php echo $id;?></option>
  • if you are using Chrome try using the developer tools and you will see in html that the option tag has value but this empty to display the name in the browser something like this: <option value="587"></option>

Browser other questions tagged

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