I have a very simple PHP script which doesn't work correctly for no reason at all, except that I am cursed:scared:!!
This is my code and then I will give you the retarded error message I am getting!!

<html>

<form action="get.php" method="GET">
<input type="text" name="myname"><br>
<input type="submit" value="click here">
</form>
</html>
<?php

$name = $_GET["myname"];
echo "Hello, $name";
?>

this should echo out Hello, and then whatever name you enter but instead it does this when I try and run it in wampserver:
Notice: Undefined index: myname in C:\wamp\www\new 3.php on line 10
Hello, !!:angry:
WHAT IN THE WORLD IS THAT FROM????
myname is defined in the second input line of the form action or am I blind????:icon_confused:
I have tried everything to get rid of this ridiculous error message but nothing helps!!:'(
Please if you could tell me what the heck is going on here I would be eternally greatful!!:icon_redface:

<html>

<form action="get.php" method="GET">
<input type="text" name="myname"><br>
<input type="submit" value="click here">
</form>
</html>
<?php

$name = $_GET["myname"];
echo "Hello, $name";
?>

'myname' is not an index in the $_GET array prior to the form being submitted.

<html>

<form action="get.php" method="GET">
<input type="text" name="myname"><br>
<input type="submit" value="click here">
</form>
</html>
<?php
if( isset( $_GET["myname"] ) ){
    $name = $_GET["myname"];
    echo "Hello, $name";
}
?>

This simple if statement looks for $_GET to be defined before it tries to execute the code that displays the array item.

I test your code in my local server, it is running fine, but initially showing
Hello,

I test your code in my local server, it is running fine, but initially showing
Hello,

"myname" is entered by the user and defined then, so how could I define it initially when no data has been entered yet??:confused:
Either way thanks for taking the time to respond!!:icon_cheesygrin:

I think mschroeder has been already done in his code.
i.e.

if( isset( $_GET["myname"] ) ){
//code
}

Thank you but I have already gotten this to work correctly due to an earlier reply!!
Zack:icon_smile:

That must be the best thread title yet!
"This is retarded!!" Calm Down man!

Thanks and yeah but it was really making no sense to me I absolutely HATE scripting in PHP because no matter what you do all you get is one parse error after another or in this case an undeclared somesuch error!!
I felt like I was going to tear my hair out because you really couldn't ask for a more basic simple script than this and it still would not run correctly!!:icon_cry:
But thanks for the validation of my clownish post title:icon_smile:!!
Zack

Member Avatar for diafol

> Thanks and yeah but it was really making no sense to me I absolutely HATE scripting in PHP because no matter what you do all you get is one parse error after another or in this case an undeclared somesuch error!!

Yep, I always blame the language when I mess up too. Join the big ego club. :)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.