Input does not send combobox value

Asked

Viewed 85 times

0

<TR>
<TD bgcolor="#CCCCCC" class="myinputstyle" size=16  >Cidade:</TD>
        <TD>
         <select name="cidades"  >
                <option value=""></option>
                <option value="sp">São Paulo</option>
                <option value="ca">Curitiba</option>
                <option value="fs">Florianopolis</option>
            </select>

            <INPUT type=text name="cidades" size="16" class="myinputstyle">

        </TD>

    <TD bgcolor="#EBEBEB" >

</TD>

This code sends the chosen option of the combobox but the value is not saved in the database, if I do not use the combobox the value is sent normally the problem only happens when I use the combobox where this error ?

2 answers

0


<TR>    
<TD bgcolor="#CCCCCC" class="myinputstyle"  >Cidade: </TD>
         <TD>
         <select name="cidade" id="cidades" >
                <option value=""></option>
                <option value="scs">São Caetano do Sul</option>
                <option value="sa">Santo André</option>
                <option value="sbc">São Bernardo do Campo</option>
            </select>
        </TD>

This code solved the problem and inserts the value in the database in case it will insert what is inside the value example, scs, sa or sbc thanks to all who answered

0

From the code you posted, it seems to me you’re defining the input and the select with the same name. Do so for example:

html form.

    <form action="teste.php" method="post">
    <table>
        <TR>
        <TD bgcolor="#CCCCCC" class="myinputstyle" size=16  >Cidade:</TD>
                <TD>
                 <select name="cidades_select">
                        <option value=""></option>
                        <option value="sp">São Paulo</option>
                        <option value="ca">Curitiba</option>
                        <option value="fs">Florianopolis</option>
                    </select>

                    <INPUT type=text name="cidades_text" size="16" class="myinputstyle">

                </TD>

            <TD bgcolor="#EBEBEB" >

        </TD>
    </tr>
    <td colspan="3">
    <input type="submit" value="Testar">
    </td>
    </table>
</form>

And take the selected value like this:

php test.

<?php
$cidade_select = $_POST['cidades_select'];
$cidade_digitado = $_POST['cidades_text'];
echo 'Cidade do Combobox: '.$cidade_select.'<br />';
echo 'Cidade do input text: '.$cidade_digitado;
  • How do I pass this code that you put inside the input ? pq the input that sends to the bd

  • Change the name of HTML inputs as it is up there. They can never be equal. Then change the PHP $_POST you currently have with the names you defined in HTML.

  • I did so and it didn’t work <INPUT type=text name="cities" size="16" class="myinputstyle" value="<? php $cidade_select = $_POST['cidades_text']; ?>">

  • The code I made was for you to send what the user typed and selected to the PHP code. For you to do it this way you have to exchange the cities_text for cidades but remembering that the name="" can never be equal in a form. In your case you had put the name cidades in <select> and <input> this cannot happen

  • Master did so now tmb keeps giving error do not know what to do <INPUT type=text name="cities" size="16" class="myinputstyle" value="<? php $cidade_select = $_POST['cidades_select']; echo $cidade_select ?>">

  • I edited the code... do it that way... The form you save in a file called formulario.html and the PHP code Voce saves as a test.php and makes the test.

  • Master if I download the team view you connect here ? did not work

  • add on facebook. fb.com/Alisson.Acioli

Show 3 more comments

Browser other questions tagged

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