Jump to content

[RESOLVIDO] Preencher uma droplist com registos vindos da base de dados


Recommended Posts

Posted

Boas pessoal,

estou a criar uma form em HTML onde incluio a tag <select> e quero preencher a droplist com os dados vindos de uma base de dados.

Nunva fiz isto, e pelo que pesquisei não ajuda muito.

Tenho o seguinte código:

<b>ADICIONAR</b>
<form method="POST" action="adiccateg2.php" enctype="multipart/form-data" >
<ul>
<li>Pai: <select name="pai"><option>Nenhum</option>
<?php
$ligacao=mysql_connect("localhost", "estagios", "estagios");
	if (!$ligacao)
	{
		print ("Problema na ligação!");
	}
$sql="select nome from categorias";
$resultado=mysql_db_query("estagios",$sql);
while ($registo=mysql_fetch_array($resultado))
		{			
			$nome=$registo["nome"];
		}
?>
<option>$sql</option>
</li>
</select>
<br/>
<li>Nome: <input type="text" name="nome" size="12"></li>
<br/>
</ul>
<p align="left"><input type="submit" value="adicionar registo">
<input type="reset" value="limpar ecra">
<p align="center">
</p>
</form>

Uma ajudinha, adradecia!! 😞

RV

Posted

Resolvido!

<b>ADICIONAR</b>
<form method="POST" action="adiccateg2.php" enctype="multipart/form-data" >
<ul>
<li>Pai: <select name="pai"><option>Nenhum</option>
<?php
mysql_connect("localhost", "estagios", "estagios") or die ("Problema na ligação!");
$sql="select nome from categorias";
$resultado=mysql_db_query("estagios",$sql);
while ($registo=mysql_fetch_array($resultado))
		{			
			$nome=$registo["nome"];
			echo '<option>' . $nome . '</option>';
		}
?>
</li>
</select>
<br/>
<li>Nome: <input type="text" name="nome" size="12"></li>
<br/>
</ul>
<p align="left"><input type="submit" value="adicionar registo">
<input type="reset" value="limpar ecra">
<p align="center">
</p>
</form>

RV

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.