Log data using Combobox

Asked

Viewed 292 times

4

I’m trying to create a real estate company On-Line, I have already built the structure, but I have no idea how to register the States, Cities and Neighborhoods of the same using a Combobox.

For those who can give an analysis I leave the address http://www.buziosnegocios.com.br/ to see that Combobox is working, because I registered directly in the BD the data of a test property in the state of Rio de Janeiro.

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

Below I relate the code I created and only managed to register the state code, state name and state acronym.

First Stage: 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>

Phase Two: Recording Status 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 now on, I don’t know how to proceed. If friends can give me a light, I’d be grateful.

Hugs to all.

  • Sergio, I’m not sure I understand your question, what exactly do you need? A better way to search the properties? What exactly is your problem with the property code structure? I always made this type of registration in the database as follows, a state table and other municipalities, there in each ad would have the register of the neighborhood, to make the search. Example of the structure here, but without the country: http://samus.com.br/web/artigo-todas_cities_do_brasil_updated_e_com_accents

  • Hello Ruggi, is the following, I’m trying to make a website for a friend who is a realtor, he would like to register the properties on own site. But I’m not getting to register real estate according to states, cities and neighborhoods. Example: A house in São Paulo, in the city of Araraquara and in the Centro neighborhood, I would have to register them with the codes of each respective state, city and neighborhood, this is what I’m not able to pull the combobox, since in it I have all the codes of states, cities and neighborhoods. Did I manage to make myself understood......

  • Continuing... I came to register the state code, the name of the state and the acronym of the state, but I stopped, I do not know how to continue the registration of the City and Neighborhood, pulling from Combobox. I published the code used to register the status so that the search for the property can be done.... It seems that I’ve stalled even more... Well that’s what I hope you’ve managed to make me understand.

1 answer

1

I don’t understand your code very well, but you can use the tag select inside the html, assigning values each item, then, if you like, by using a if, by assigning a more complete value to each item in the combobox, still includes a very simple method of inserting this value into a table, thus:

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')';
?>
  • Thank you for your attention to my problem Jorge, I will try to do with your reasoning, given the result you can or even to ask questions if they arise. Once again QUARREL.

Browser other questions tagged

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