What is it missing?

Asked

Viewed 61 times

-2

<?php
    $teste = $_POST['Nome'];
?>

<html>
    <head>
        <title>O</title>
    </head>
<body>
    <form name="f_cad" method="POST"/>
        <input type="text" name="Nome"/>
</body>
</html>

Notice: Undefined index: Name in D: wamp www cursophp all.php on line 2

What’s missing? It’s all right.

  • 2

    "- It’s all right" is more wrong than right. Otherwise it would at least be working. Isn’t it?! The error message means that if the index Nome is not set, you should set it or else "check if it is set".

  • 2

    There are other problems in the code, but it would be good to start eliminating these XML things by improperly closing the tags (/>) and although HTML5 is permissive (what I consider a specification defect), it pays to do the right thing and close the form.

2 answers

1

The code is working perfectly, Warning appears because at the time you open the page you have not submitted the form so the variable $_POST['Name'] does not exist yet.

In the suggested test above, you will see "Nothing has been received" if you have not submitted the form instead of the Warning that gave you and from the moment you submit it, that is, from the moment you send a variable $_POST['Name'], it will give you the result on the screen.

I hope you understand

1


The form needs to "embrace" the components that should be sent to the server.

<form name="f_cad" method="POST">
   <input type="text" name="Nome" />
</form>

To test do so.

<?php
if(isset($_POST['Nome'])) {
    print "Foi recebido :: " . $_POST['Nome'];
} else {
    print "Nada foi Recebido";
}
?>
  • Calm down, I went to test and made a mistake

  • Well, the php test worked, the script printed on the "Nothing was received" screen, even having the same name, in name, and in $_POST. I think I’ll try the GET method.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.