Input does not send value from combobox

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 is the error?     

asked by anonymous 21.08.2016 / 00:11

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 responded

    
19.09.2016 / 04:30
0

From the code you posted, I think you're setting input and select to the same name. Do so for example:

form.html

    <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 get the selected value like this:

test.php

<?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;
    
21.08.2016 / 00:22