← Desenvolvimento

Campo de texto

Lida 8508 vezes

Offline

OFFICER 
Membro
Mensagens 2076 Gostos 0
Troféus totais: 29
Trófeus: (Ver todos)
Super Combination Combination Topic Starter 10 Poll Votes Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2

Ah, espera. Como a variável ao inicio não é preenchida é a razão de aparecer o erro, pois o else actua. Então tens que fazer algo assim:

Código: [Seleccione]
<?php
$respostacorrecta 
"3"
if &#40;isset&#40;$_POST[submeter&#93;&#41; && $_POST[camporesposta&#93; == $respostacorrecta&#41; &#123;
Header&#40;"Location&#58; nivel1.php"&#41;;
&#125;
if &#40;isset&#40;$_POST[submeter&#93;&#41; && $_POST[camporesposta&#93; != $respostacorrecta&#41; &#123;
echo "A resposta está incorrecta!";
&
#125; 
elseif &#40;isset&#40;$_POST[submeter&#93;&#41; && $_POST[camporesposta&#93; == ""&#41; &#123;
echo "O campo da resposta está vazio, tenta de novo!";
&
#125;
echo '<p align="center">
<img border="0" src="logo_index.jpg" width="686" height="112"></p>
<body link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF" text="#FFFFFF" bgcolor="#000000" style="text-align&#58; center">
<form name="resposta" method="post" action="">
<table border="0">
<tr><td><b>Quantas riscas têm o Logotipo da marca Adidas? 3, 4 ou 5?</b></td></tr>
<tr><td><input name="camporesposta" type="text" size="30"></td></tr>
<tr><td><input type="submit" name="submeter" value="Submeter!"></td></tr></form>'
;
?>
Offline

kingless 
Membro
Mensagens 857 Gostos 0
Troféus totais: 27
Trófeus: (Ver todos)
Super Combination Combination Topic Starter Poll Voter Poll Starter Level 5 Level 4 Level 3 Level 2 Level 1

Citação de: "OFFICER"
Citação de: "kingless"
Aqui:
Código: [Seleccione]

<form name="resposta" method="post" action="">


Coloca assim:
Código: [Seleccione]

<form name="resposta" method="post" action="<?__FILE__?>">


Muito gostas tu de complicar..isso também não é necessário. Sempre usei sem nada e já vi muita gente usar e não era necessário isso.

Basta colocares tudo em php, que assim ele já conta com o if no formulário..fica algo assim:

Código: [Seleccione]
<?php
$respostacorrecta 
"3";
if &
#40;isset&#40;$_POST[submeter&#93;&#41; && $_POST[camporesposta&#93; == $respostacorrecta&#41; &#123;
Header&#40;"Location&#58; nivel1.php"&#41;;
&#125; else &#123;
echo "A Resposta está errada";
&
#125;
echo '<p align="center">
<img border="0" src="logo_index.jpg" width="686" height="112"></p>
<body link="#FFFFFF" vlink="#FFFFFF" alink="#FFFFFF" text="#FFFFFF" bgcolor="#000000" style="text-align&#58; center">
<form name="resposta" method="post" action="">
<table border="0">
<tr><td><b>Quantas riscas têm o Logotipo da marca Adidas? 3, 4 ou 5?</b></td></tr>
<tr><td><input name="camporesposta" type="text" size="30"></td></tr>
<tr><td><input type="submit" name="submeter" value="Submeter!"></td></tr></form>'
;
?>


OFFICER Ok até a proxima  :wink: