Jump to content
Fórum Script Brasil
  • 0

Erro Na Variavel


William

Question

fiz um scrip simples pra ver com funciona, mais da um erro:

Notice: Undefined variable: texto in c:\arquivos de programas\apache group\apache\htdocs\teste\var.php on line 6

o script q fiz roda é esse:

<html>

<head><title>Aprendendo PHP</title></head>

<body>

<?php

if ($texto != "")

echo "Você digitou \"$texto\"<br><br>";

?>

<form method=post action="<? echo $PATH_INFO; ?>">

<input type="text" name="texto" value="" size=10>

<br>

<input type="submit" name="sub" value="Enviar!">

</form>

</body>

</html>

o q tem de errado?

Link to comment
Share on other sites

5 answers to this question

Recommended Posts

  • 0

Tenta isso:

<html>

<head><title>Aprendendo PHP</title></head>

<body>

<?php

if ($texto != "") {

echo "Você digitou \"$texto\"<br><br>";

}

else {

?>

<form method=post action="<? echo $PATH_INFO; ?>">

<input type="text" name="texto" value="" size=10>

<br>

<input type="submit" name="sub" value="Enviar!">

</form>

<?}

?>

</body>

</html>

Link to comment
Share on other sites

  • 0

Oi William,

este erro esta acontecendo quando você executa o script pela primeira vez e o script ainda não sabe quem é a variavel texto.

Para corrigira faca o seguinte:

<html>

<head><title>Aprendendo PHP</title></head>

<body>

<?php

if (isset ($texto)){

if ($texto != ""){

echo "Você digitou \"$texto\"<br><br>";

}

}else{

?>

<form method=post action="<? echo $PATH_INFO; ?>">

<input type="text" name="texto" value="" size=10>

<br>

<input type="submit" name="sub" value="Enviar!">

</form>

<?

}

?>

Espero ter ajudado

</body>

</html>

Link to comment
Share on other sites

  • 0

depois q mudei o script da um erro quando eu aperto em enviar.

Forbidden

You don't have permission to access /Teste/<br /><b>Notice</b>: Undefined variable: PATH_INFO in <b>c:/arquivos de programas/apache group/apache/htdocs/teste/var.php</b> on line <b>12</b><br /> on this server.

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

Apache/1.3.29 Server at localhost Port 80

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      651.8k
×
×
  • Create New...