Answer the question
In order to leave comments, you need to log in
Why doesn't the POST example from the php.net manual work?
Hello. Please help the student to understand. I enter an example using POST
<?php
echo 'Привет ' . htmlspecialchars($_POST["name"]) . '!';
?>
Notice: Undefined index: name in /User/site.local/php/test.php on line 2
Hi!
It is assumed that the user sent via POST name=Hannes
The result of this example will be something like this:
Hello Hannes!
Answer the question
In order to leave comments, you need to log in
the first time you open there is no post[name] only when you send something so you need to check for the post
(not sure)
Hannes is the name that was sent to the script
htmlspecialcharacters: php.net/htmlspecialchars
Type your site address in the line /?name=Hannes
And replace the script with
<?php
echo 'Hello ' . htmlspecialchars($_REQUEST["name"]) . '!';
?>
and see what happens.
For the post method to work, you need to submit the form.
<form>
<input type="text" name="name">
<button>Отправить</button>
</form>
<?php
echo 'Привет ' . htmlspecialchars($_REQUEST["name"]) . '!';
?>
It is written: It is understood that the user sent via POST name=Hannes
Did you send?
For a start, read how to send this same POST in general, and how it differs from GET, for example.
Usually POST is used to send data from a form to an html page.
Add to file
<form method="POST">
<input type="text" name="name"><br>
<input type="submit" value="submit" name="submitMe">
</form>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question