Thank you for your cooperation.
I wanted to generate a form tag in PHP and reflect the data I sent in input and submit on the same page, but it didn't work.
The following is the situation.
test.php
file
<form name="name" action="test.php" method="GET">
<Label for="name">Name:</Label>
<input name="name" type="text">
<input type="submit" value="send">
</form>
<pre>
<?php
echohtmlspecialchars($_GET["name"]);
?>
</pre>
*Tags such as html and body are not included.
On the same page, if you write any name in the name field and press Send, you will receive the Undefined index:name
error.
When I looked into it, it seemed that the error occurred because ($_GET["name"]);
was undefined when I first accessed test.php
, and
As a countermeasure,
if(!empty($_POST["submit"])){}
Or
if(isset($_POST["submit"])){}
Use to verify definitions
There was an article saying that, but what does the definition of $_GET["name"]
refer to in the text?
In the tag of the information sent from the form
, I wondered if I could get the "name"
with the GET
variable defined by name="name"
.
Do I need to define it separately?
I'm sorry to trouble you, but I'd appreciate it if you could give me some advice.
php form
Please note that the content of the error is not an undefined variable, but
You are referring to an undefined array index.
If you try to access a key that does not have a variable in its own array, you get a similar error.Try it.
Normally, if it is a variable of your own array, you can declare an index.
$_GET
cannot be declared because it is a variable in a global scope array defined in PHP and must be used after checking if it exists as in question.
What does the definition of $_GET["name"] refer to in the text?
So
This is the key definition for the array in $_GET
.
© 2024 OneMinuteCode. All rights reserved.