Ir para conteúdo

POWERED BY:

Arquivado

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

Renê Ribeiro Mendes

ComboBOx via POST

Recommended Posts

Bom Dia, Tenho um exemplo funcionando na tela de cadastro conforme abaixo, porém estou tentando passar via POST o "name" do select porém não funciona. Estou passando desta forma:

$grupo = $_POST[grupo];

Porém o registro selecionado não é transportado.

----------------------------------------------------------------------------


<select name='grupo'>
<option>
Escolha um Curso
</option>
<?php
include "conf.php";
$sql = "select * from curso";
$executar = mysql_query($sql) or die (mysql_error());
while($reg = mysql_fetch_array($executar))
{
?>
<option value="<?php $reg['id'];?>">
<?php echo $reg['periodo']; ?>
</option>
<?php
}
?>
</select>

Compartilhar este post


Link para o post
Compartilhar em outros sites

adicone aspas,

 

$grupo = $_POST['grupo'];
 

 

aparece algum erro?

Compartilhar este post


Link para o post
Compartilhar em outros sites

o method do form esta como post?

Compartilhar este post


Link para o post
Compartilhar em outros sites

posta ai o seu formulario.

Compartilhar este post


Link para o post
Compartilhar em outros sites

CadAluno.php

 

<?php
$grupo = $_POST['grupo'];
ECHO $grupo;

include ("conf.php");

mysql_query("INSERT INTO ALUNO (NOME,ENDERECO,CIDADE,UF, EMAIL, FONE, CURSO, SEMESTRE)
VALUES ('$_POST[nome]',
'$_POST[endereco]',
'$_POST[cidade]',
'$_POST[uf]',
'$_POST',
'$_POST[fone]',
'$_POST[grupo]',
'$_POST[semestre]')");

?>

 

 

CadastroAluno.php

 

<html>
<head>
<title> Cadastro de Aluno </title>
</head>
<body>
<form name= "form1" method= "POST" action="cadAluno.php">

<label> Nome: </label>
<input type= "text" name="nome" value="" size="30" maxlength="30"> </br>
<br>
<label> Endereço: </label>
<input type= "text" name="endereco" value="" size="25" maxlength="25"> </br>
<br>
<label> Cidade: </label>
<input type= "text" name="cidade" value="" size="15" maxlength="15"> </br>
<br>
<label> UF: </label>
<input type= "text" name="uf" value="" size="2" maxlength="2" maxlength="2"> </br>
<br>
<br>
<label> E-mail: </label>
<input type= "text" name="email" value="" size="30" maxlength="30"> </br>
<br>
<br>
<label> Fone: </label>
<input type= "text" name="fone" value="" size="11" maxlength="11"> </br>
<br>
<select name='grupo'>
<option>
Escolha um Curso
</option>
<?php
include "conf.php";
$sql = "select * from curso";
$executar = mysql_query($sql) or die (mysql_error());
while($reg = mysql_fetch_array($executar))
{
?>
<option value="<?php $reg['id'];?>">
<?php echo $reg['periodo']; ?>
</option>
<?php
}
?>
</select>

<label> Semestre: </label>
<input type= "text" name="semestre" value="" size="2" maxlength="2"> </br>
<br>
<input type= "submit" name="cadastrar" value="Cadastrar"> </br>
<br>
<input type= "submit" name="alterar" value="Alterar"> </br>
<br>
<input type= "submit" name="excluir" value="Excluir"> </br>
<br>
<input type= "submit" name="limpar" value="Limpar"> </br>

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

Compartilhar este post


Link para o post
Compartilhar em outros sites

veja se o value do option esta preenchido.

 

coloque um echo esse nessa linha

 

<option value="<?php $reg['id'];?>">

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.