Ir para conteúdo
Fórum Script Brasil
  • 0

(Resolvido) Função para carregar combo com UF dinamicamente


Recife

Pergunta

Ola pessoal,

Sou iniciante em PHP, e estou estudando criando um cadastro de usuário,porém tem um combo em que criei uma função mais não esta carregando abaixo segue o codigo:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Cadastro de usuários</title>
    </head>
    <?php
        function lista_estados($_nome_campo="USR_UF",$MULT=FALSE){
            $_ufs = array("SP" => "São Paulo",
                        "RJ" => "Rio de Janeiro",
                        "MG" => "Minas Gerais",
                        "BA" => "Bahia",
                        "PE" => "Pernambuco",
                        "RS" => "Rio Grande do Sul",
                        "AM" => "Amazonas",
                        "CE" => "Ceará",
                        "AL" => "Alagoas",
                        "SE" => "Sergipe",
                        "PB" => "Paraíba");
            $_ret ="<SELECT NAME='$_nome_campo'";
            $_ret.=($MULT) ?  " MULTIPLE" : "";
            $_ret.=">\n";
            foreach($_ufs as $_chv => $_vlr){
               $_ret.="<OPTION VALUE='$_chv'>$_vlr</OPTION>\n";
            }
            $_ret.="</SELECT>\n";
            return $_ret;
          }
        ?>

    <body>
        <form name="usr" method="post" action="cadastra_usuario.php5">
            <table border="0" cellpadding="5" cellspacing="5">
                <tr>
                    <td colspan="2" height="30" bgcolor="#8CDAFF">
                        <b>Cadastro de Usuário</b>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" height="30"><font color="#0000A0">
                            <b>Informe seus dados:</b></font>
                    </td>
                </tr>
                <tr>
                    <td width="25%" height="30">Nome:</td>
                    <td height="30" >
                        <input type="text" name="USR_NOME" size="30">
                    </td>
                </tr>
                <tr>
                    <td width="10%" height="30" valign="top">Endereço:</td>
                    <td height="30">
                        <textarea name="USR_ENDERECO" cols="60" rows="5"></textarea>
                    </td>
                </tr>
                <tr>
                    <td width="10%" height="30">Bairro:</td>
                    <td height="30">
                        <input type="text" name="USR_BAIRRO" size="30">
                    </td>
                </tr>
                <tr>
                    <td width="10%" height="30" class="login">Cidade:</td>
                    <td height="30">
                        <input type="text" name="USR_CIDADE" size="30">
                    </td>
                </tr>
                <tr>
                    <td width="10%" height="30" class="login">Estado:</td>
                    <td height="30">
                        <?=lista_estados();?>
                    </td>
                </tr>
                <tr>
                    <td width="10%" height="30">E-mail:</td>
                    <td height="30">
                        <input type="text" name="USR_EMAIL" size="30">
                    </td>
                </tr>
                <tr>
                    <td width="10%" height="30">Login:</td>
                    <td height="30">
                        <input type="text" name="USR_LOGIN" size="10">
                    </td>
                </tr>
                <tr>
                    <td width="10%" height="30">Senha:</td>
                    <td height="30">
                        <input type="password" name="USR_SENHA" size="10">
                    </td>
                </tr>
                <tr>
                    <td width="20%" height="30">Confirmação de Senha:</td>
                    <td height="30" align="left">
                        <input type="password" name="USR_SENHA2" size="10">
                    </td>
                </tr>
                <tr heigth="60" valign="bottom">
                    <td width="20%"></td>
                    <td height="30" valign="bottom">
                        <input type="submit" value="    OK    ">   
                        <input type="reset" value="    Limpar    ">
                    </td>
                </tr>

            </table>
        </form>
    </body>
</html>

Quando executo o script os estados não aparecem, só o nome estado.

Onde pode estar o erro,pois não estou conseguindo identificar?

Link para o comentário
Compartilhar em outros sites

1 resposta a esta questão

Posts Recomendados

  • 0
Ola pessoal,

Sou iniciante em PHP, e estou estudando criando um cadastro de usuário,porém tem um combo em que criei uma função mais não esta carregando abaixo segue o codigo:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Cadastro de usuários</title>
    </head>
    <?php
        function lista_estados($_nome_campo="USR_UF",$MULT=FALSE){
            $_ufs = array("SP" => "São Paulo",
                        "RJ" => "Rio de Janeiro",
                        "MG" => "Minas Gerais",
                        "BA" => "Bahia",
                        "PE" => "Pernambuco",
                        "RS" => "Rio Grande do Sul",
                        "AM" => "Amazonas",
                        "CE" => "Ceará",
                        "AL" => "Alagoas",
                        "SE" => "Sergipe",
                        "PB" => "Paraíba");
            $_ret ="<SELECT NAME='$_nome_campo'";
            $_ret.=($MULT) ?  " MULTIPLE" : "";
            $_ret.=">\n";
            foreach($_ufs as $_chv => $_vlr){
               $_ret.="<OPTION VALUE='$_chv'>$_vlr</OPTION>\n";
            }
            $_ret.="</SELECT>\n";
            return $_ret;
          }
        ?>

    <body>
        <form name="usr" method="post" action="cadastra_usuario.php5">
            <table border="0" cellpadding="5" cellspacing="5">
                <tr>
                    <td colspan="2" height="30" bgcolor="#8CDAFF">
                        <b>Cadastro de Usuário</b>
                    </td>
                </tr>
                <tr>
                    <td colspan="2" height="30"><font color="#0000A0">
                            <b>Informe seus dados:</b></font>
                    </td>
                </tr>
                <tr>
                    <td width="25%" height="30">Nome:</td>
                    <td height="30" >
                        <input type="text" name="USR_NOME" size="30">
                    </td>
                </tr>
                <tr>
                    <td width="10%" height="30" valign="top">Endereço:</td>
                    <td height="30">
                        <textarea name="USR_ENDERECO" cols="60" rows="5"></textarea>
                    </td>
                </tr>
                <tr>
                    <td width="10%" height="30">Bairro:</td>
                    <td height="30">
                        <input type="text" name="USR_BAIRRO" size="30">
                    </td>
                </tr>
                <tr>
                    <td width="10%" height="30" class="login">Cidade:</td>
                    <td height="30">
                        <input type="text" name="USR_CIDADE" size="30">
                    </td>
                </tr>
                <tr>
                    <td width="10%" height="30" class="login">Estado:</td>
                    <td height="30">
                        <?=lista_estados();?>
                    </td>
                </tr>
                <tr>
                    <td width="10%" height="30">E-mail:</td>
                    <td height="30">
                        <input type="text" name="USR_EMAIL" size="30">
                    </td>
                </tr>
                <tr>
                    <td width="10%" height="30">Login:</td>
                    <td height="30">
                        <input type="text" name="USR_LOGIN" size="10">
                    </td>
                </tr>
                <tr>
                    <td width="10%" height="30">Senha:</td>
                    <td height="30">
                        <input type="password" name="USR_SENHA" size="10">
                    </td>
                </tr>
                <tr>
                    <td width="20%" height="30">Confirmação de Senha:</td>
                    <td height="30" align="left">
                        <input type="password" name="USR_SENHA2" size="10">
                    </td>
                </tr>
                <tr heigth="60" valign="bottom">
                    <td width="20%"></td>
                    <td height="30" valign="bottom">
                        <input type="submit" value="    OK    ">   
                        <input type="reset" value="    Limpar    ">
                    </td>
                </tr>

            </table>
        </form>
    </body>
</html>

Quando executo o script os estados não aparecem, só o nome estado.

Onde pode estar o erro,pois não estou conseguindo identificar?

para solução do problema na chamada da função deve ser da seguinte forma:

<?php echo lista_estados();?>

dessa forma dara certo.

[Problema resolvido]

Link para o comentário
Compartilhar em outros sites

Participe da discussão

Você pode postar agora e se registrar depois. Se você já tem uma conta, acesse agora para postar com sua conta.

Visitante
Responder esta pergunta...

×   Você colou conteúdo com formatação.   Remover formatação

  Apenas 75 emoticons são permitidos.

×   Seu link foi incorporado automaticamente.   Exibir como um link em vez disso

×   Seu conteúdo anterior foi restaurado.   Limpar Editor

×   Você não pode colar imagens diretamente. Carregar ou inserir imagens do URL.



  • Estatísticas dos Fóruns

    • Tópicos
      152,2k
    • Posts
      652k
×
×
  • Criar Novo...