Ir para conteúdo

POWERED BY:

Arquivado

Este tópico foi arquivado e está fechado para novas respostas.

CrazyLOL

[Resolvido] problema com combox ( select )

Recommended Posts

Galera seguinte, não sei o que está errado, estou tentando preencher uma Lista com dados do banco de dados porém qndo jogo para rodar o site não aparece erro nao aparece nada... não sei se tem algum erro no meu codigo, abaixo está ele:

 

 

 <tr>
     <td width="159"><span class="style1">Concessionaria:</span></td>
     <td width="531"> <select name="_con" id="_con">
     <option>Selecione...</option>
  <?php
  include("config.php");
  $sql = "SELECT * FROM lojas";
  $conce = mysql_query($sql);	 
  echo "conectou"; 

  while($reg = mysql_fetch_array($conce))  {
  ?>
     <option><?php $reg=['concessionaria'] ?></option>
    <?
  }
  ?>
     </select> </td>
   </tr>

 

acima só coloquei o trecho que é da Lista, já tentei de tudo que é forma , mas não está aparecendo.

Compartilhar este post


Link para o post
Compartilhar em outros sites

tente

<option><?php echo $reg=['concessionaria'] ?></option>

 

n esqueça do atributo value dentro do option

 

veja se a open shorttag esta habilitada

 

<?
  }
?>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Está habilitada sim, já tinha feito o teste tbm adicionando o echo, mesmo assim não ocorre nada.. :/ também já adicionei valor na value, e retirei e continuo dando nada...

Compartilhar este post


Link para o post
Compartilhar em outros sites

quando você abre a pgina ela fica totalmente em branco?

 

ligue a exibição dos erros:

 

ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);

Compartilhar este post


Link para o post
Compartilhar em outros sites

echo $reg=['concessionaria'] ????

 

$reg é igual ao índice concessionaria?

 

...$reg['concessionaria']...

 

Compartilhar este post


Link para o post
Compartilhar em outros sites

Sim fica a tela toda branca e não mostra erro.. se eu retiro o trecho do select ai aparece a minha pagina...

adicionei o codigo mais continuo tudo branco...

 

@Hiago sim é para pegar o registro da minha tabela concessionaria ( seria no bd o nome da loja )

 

 

para melhor entender aqui esta o arquivo todo, desse cadastro.

 

<?php
  include("config.php");
  ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
font-family: Tahoma;
font-size: 13px;
font-weight: bold;
}
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
 <table width="700" border="0" align="center">
   <tr>
     <td width="159"><span class="style1">Concessionaria:</span></td>
     <td width="531"><?php

  $sql = "SELECT * FROM lojas";
  $conce = mysql_query($sql) or die mysql_error();

  while($reg = mysql_fetch_array($conce))  {
  ?> <select name="_con" id="_con">
     <option value="0">Selecione...</option>

     <option value="<?php echo $reg=['id'] ?>"><?php echo $reg=['concessionaria'] ?></option>

     </select>  <?php
  }
  ?> </td>
   </tr>
   <tr>
     <td><span class="style1">Nome colaborador:
         <label></label>
     </span></td>
     <td><input type="text" name="textfield2" id="textfield2" /></td>
   </tr>
   <tr>
     <td><span class="style1">Usuario:
         <label></label>
     </span></td>
     <td><input type="text" name="textfield3" id="textfield3" /></td>
   </tr>
   <tr>
     <td><span class="style1">Senha:
         <label></label>
     </span></td>
     <td><input type="text" name="textfield4" id="textfield4" /></td>
   </tr>
   <tr>
     <td><span class="style1">Repetir a senha:
         <label></label>
     </span></td>
     <td><input type="text" name="textfield" id="textfield" /></td>
   </tr>
   <tr>
     <td><span class="style1">Acesso:</span></td>
     <td><input type="text" name="textfield5" id="textfield5" /></td>
   </tr>
   <tr>
     <td> </td>
     <td> </td>
   </tr>
 </table>
 <p> </p>
</form>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

n aparece nenhum erro?

tem algum registro no banco?

o config.php pode ter algum...

Compartilhar este post


Link para o post
Compartilhar em outros sites

Tem registro no banco sim, e o config tá ok algumas outras funções que puxo através dla não tem erro..

abaixo o config.php para voce ver:

 

<?php
session_start();
$host = "localhost";
$user = "root";
$password = "";
$dbname = "loja_teste";

$con = mysql_connect($host, $user, $password) or die("Erro ao tentar se conectar!");
mysql_select_db($dbname)or die("Erro ao selecionar o banco!");


?>

 

Tá complicado.. :(

Compartilhar este post


Link para o post
Compartilhar em outros sites

Brother, não se você já resolveu o problema.

 

mas tenta aí....

 

<?php

ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);



include("config.php");

$sql = "SELECT * FROM lojas";
$conce = mysql_query($sql) or die mysql_error();

$select = array();
while($reg = mysql_fetch_array($conce)) {
$chave = $reg=['id'];
$valor = $reg=['concessionaria'];

$select[chave] = valor;
}

if( count($select) == 0 )
die("Falta montar a combo descentemente");

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
.style1 {
       font-family: Tahoma;
       font-size: 13px;
       font-weight: bold;
}
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
 <table width="700" border="0" align="center">
   <tr>
     <td width="159"><span class="style1">Concessionaria:</span></td>
     <td width="531"><select name="_con" id="_con">
						<option value="0">Selecione...</option>
						<?php foreach($select as $chave => $valor)?>
							<option value="<?php echo $chave ?>"><?php echo $valor ?></option>
				  </select>
  </td>
   </tr>
   <tr>
     <td><span class="style1">Nome colaborador:
         <label></label>
     </span></td>
     <td><input type="text" name="textfield2" id="textfield2" /></td>
   </tr>
   <tr>
     <td><span class="style1">Usuario:
         <label></label>
     </span></td>
     <td><input type="text" name="textfield3" id="textfield3" /></td>
   </tr>
   <tr>
     <td><span class="style1">Senha:
         <label></label>
     </span></td>
     <td><input type="text" name="textfield4" id="textfield4" /></td>
   </tr>
   <tr>
     <td><span class="style1">Repetir a senha:
         <label></label>
     </span></td>
     <td><input type="text" name="textfield" id="textfield" /></td>
   </tr>
   <tr>
     <td><span class="style1">Acesso:</span></td>
     <td><input type="text" name="textfield5" id="textfield5" /></td>
   </tr>
   <tr>
     <td> </td>
     <td> </td>
   </tr>
 </table>
 <p> </p>
</form>
</body>
</html>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Não deu certo Flavio, já to começando a pensar que pode ser algum bug, no apache ou algo assim, porque não pode ser que isso não funcione...

 

<_<

Compartilhar este post


Link para o post
Compartilhar em outros sites

Cara, que drama, bug no apache?

 

Vamos analisar:

 

<td width="531"><?php

 

$sql = "SELECT * FROM lojas";

$conce = mysql_query($sql) or die mysql_error();

 

Até aqui tudo bem.

 

 

while($reg = mysql_fetch_array($conce)) {

 

Agora para tudo, você tá vendo que você tá criando o select dentro do while? Se sim acho que você precisa dar uma estudada na documentação, pois o while é uma estrutura de loop, sendo assim todo esse trecho que está dentro dele será repetido em loop de acordo com o while.

 

?> <select name="_con" id="_con">

<option value="0">Selecione...</option>

 

<option value="<?php echo $reg=['id'] ?>"><?php echo $reg=['concessionaria'] ?></option>

 

O mysql_fetch_array, como diz retorna um array, sendo assim não use $reg=['concessionaria'], que não vai funcionar nunca. Dá uma estudada em array.

 

 

</select> <?php

}

?> </td>

Compartilhar este post


Link para o post
Compartilhar em outros sites

Então tinha feito isso para testar, não percebi e acabei colocando esse codigo...

Mas não foi não...

Até mesmo usei o codigo que o flavio passou e não deu certo também.. :/

 

Abraç

Compartilhar este post


Link para o post
Compartilhar em outros sites

1º e principal erro: nessa linha:

<option value="<?php echo $reg=['id'] ?>"><?php echo $reg=['concessionaria'] ?></option>

tire os sinais de igual nos "echos"..

.. a bem da verdade, essa dica até já havia sido passada:

http://forum.imasters.com.br/topic/464416-problema-com-combox-select/page__view__findpost__p__1840041

bom, mas nessa linha tb tem erro (faltou parênteses):

$conce = mysql_query($sql) or die mysql_error();

o correto:

$conce = mysql_query($sql) or die(mysql_error());

o restante é + questão de intercalar html e php; tente assim:

 

<?php
         include("config.php");
         ini_set('display_errors',1);
ini_set('display_startup_erros',1);
error_reporting(E_ALL);

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<style type="text/css">
<!--
.style1 {
       font-family: Tahoma;
       font-size: 13px;
       font-weight: bold;
}
-->
</style>
</head>

<body>
<form id="form1" name="form1" method="post" action="">
 <table width="700" border="0" align="center">
   <tr>
     <td width="159"><span class="style1">Concessionaria:</span></td>
     <td width="531"><?php

         $sql = "SELECT * FROM lojas";
         $conce = mysql_query($sql);?>
	  <select name="_con" id="_con">
<?php
while ($reg = mysql_fetch_array($conce))
{
?> 
<option value="<?php echo $reg['id'] ?>"><?php echo $reg['concessionaria'] ?></option>
<?php
}
   ?> </select>  </td>
   </tr>
   (resto do form ok, acho)
</body>
</html>

OBS:

(resto do form ok, acho)

não.. acho q falta tb 1 botão submit..

Compartilhar este post


Link para o post
Compartilhar em outros sites

×

Informação importante

Ao usar o fórum, você concorda com nossos Termos e condições.