Jump to content

<?PHP - Duvida ?>


Recommended Posts

Posted

O Que é que me falta aqui para que a opção apareça na caixa de texto ? :wallbash:

<html>
<body>
<input name="opcao" type="radio" value="1" />
<input name="opcao" type="radio" value="2" />
<input name="opcao" type="reset" />
<input 
<?php
$opcao = $_POST['opcao']; 
if ($opcao == 1){   $votar = 1;
}
else if ($opcao == 2)
{   
$votar = 2;
}
echo $votar;
?>
</body>
</html>
Posted
<?php
$opcao = $_POST['opcao']; 
if(isset($_POST['enviar']) AND $opcao != "") {
switch($opcao) {
case  1: $votar = 1;
break;
case 2: $votar = 2;
break;
}
echo $votar;
} else {
?>
<html>
<body>
<form method="post" action="<?__FILE__?>">
<input name="opcao" type="radio" value="1">
<input name="opcao" type="radio" value="2">
<input name="enviar" type="submit" value="Submeter">
<input name="reset" type="reset" value="Apagar">
</form>
</body>
</html>
<? } ?>

Ainda não testei mas acho que vai funcionar bem. O problema no teu codigo estava na "form" não colocaste, se quiseres aprender mais um pouco sobre isto tens aqui um pequeno tutorial http://phpbrasil.com/articles/article.php/id/719

  • 2 weeks later...

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.