Register data using ComboBox

4

I'm trying to create an On-Line real estate, I've been able to build the structure, but I have no idea how to register the States, Cities and Neighborhoods using a ComboBox.

For those of you who can give a review I leave the address link to see that the ComboBox is working, because I registered directly in the BD the data of a property for testing in the state of Rio de Janeiro.

If friends can give me an idea of how to register real estate ads with the ComboBox, or otherwise I will be very grateful.

Below I list the code that I created and was only able to register the state code, state name and State Acronym.

First phase: Selecting the state.

            <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />

        <?php
        if(isset($_POST['enter'])){
        $dp =  $_POST['cod_estado'];
            echo "<script language='javascript'>window.location='cadastrar_anuncio_2.php?cod_estado=$dp'</script>";
        }
        ?>
        <form name="enter" method="post" action="" enctype="multipart/form-data">
        <label>Selecione o estado de origem do Imóvel</label><br /><br />
        <select name="cod_estado">
        <?php
        include 'conexao.php';
        $select = mysql_query("SELECT * FROM estados ORDER BY nome_estado ASC");
        while($res = mysql_fetch_array($select)){
        ?>
        <option value="<?php echo $estados =  $res['cod_estado'];?>"><?php echo $estados =  $res['nome_estado'];?></option>
        <?php } ?>
        </select><br /><br />
        <input class="input" type="submit" name="enter" value="Avançar"/>
        </form>

Second phase: Recording state data.

            <meta http-equiv="Content-Type" content="text/html; charset=windows-1252" />
        <?php
        if(isset($_POST['cadastrar'])){
        $dp =  $_POST['cod_estado'];
            echo "<script language='javascript'>window.location='cadastrar_anuncio_3.php?cod_estado=$dp'</script>";
        }
        ?>

        <form name="cadastrar" action="" method="post" enctype="multipart/form-data" >

        <?php
        $dp =  $_POST['cod_estado'];
        include "conexao.php";
        $cod_estado = $_GET['cod_estado'];
        $query = mysql_query("SELECT * FROM estados WHERE cod_estado = '$cod_estado'");
        $res = mysql_fetch_array($query);

        if(isset($_POST['cadastrar'])){
            $nome_estado = $_POST['nome_estado'];
            $uf = $_POST['uf']; 
            $cod_estado = $_GET['cod_estado'];  

            $insert = mysql_query("INSERT INTO anuncio VALUES ('NULL', '$cod_estado', '$nome_estado', '$uf',  '$cod_cidade', '$nome_cidade', '$cod_bairro', '$nome_bairro', '$foto01')")or die(mysql_error());
        if($insert == ''){
            echo "<script language='javascript'>
            window.alert('Erro ao cadastrar Anuncio!!!');
            </script>";
        }else{
            echo "<meta http-equiv='refresh' content='0; URL= cadastrar_anuncio_3.php?cod_estado=".$cod_estado."'>
            <script language='javascript'>
            window.alert('Cidade cadastrada com sucesso!!!');
            </script>";
        }}
        $dp =  $_POST['cod_estado'];
        include 'conexao.php';
            $uf = $_GET['uf'];
            $nome_estado = $_GET['nome_estado'];
            $cod_estado = $_GET['cod_estado'];
            $query = mysql_query("SELECT * FROM estados WHERE cod_estado = '$cod_estado'");
            $res = mysql_fetch_array($query);
        ?>  
        <input size="1" type="text" name="cod_estado" value="<?php echo $res['cod_estado']; ?>" readonly="readonly"/>
        <input size="20" type="text" name="nome_estado" value="<?php echo $res['nome_estado']; ?>" readonly="readonly"/>
        <input size="1" type="text" name="uf" value="<?php echo $res['uf']; ?>" readonly="readonly"/>
        <input type="submit" name="cadastrar" value="Cadastrar" />
        </form>

From then on I packed, I do not know how to proceed. If friends can give me a light, I'll be grateful.

Hugs to all.

    
asked by anonymous 17.11.2015 / 12:47

1 answer

1

I do not quite understand your code, but you can use the select tag inside the html, assigning values to each item, then, if you want, using a if , assigning a more complete value to each item of combobox , still includes a very simple method of inserting this value into a table, like this:

HTML

<form action="POST" action="index.php"> 
<select name="estado">
  <option value="rj">rio de janeiro</option>
  <option value="sp">são paulo</option>
</select> 

PHP

  <?php
$local = $_POST['estado'];
if ($local == rj){
  $local = "Rio de Janeiro";
  echo"$local";/*aqui retornaria Rio de janeiro*/
}elseif ($local == sp){
  $local = "São Paulo";
  echo"$local";/*aqui retornaria São Paulo*/
  $insere = "NSERT INTO tabela (local) VALUES ('$local')";
  $insere_query = 'mysql_query('$insere')';
?>
    
18.11.2015 / 18:15