954,597 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

This is retarded!!

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">
<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:

zlloyd1
Light Poster
41 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 
<html>

<form action="get.php" method="GET">
<input type="text" name="myname">
<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">
<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['myname'] to be defined before it tries to execute the code that displays the array item.

mschroeder
Work Harder
Team Colleague
666 posts since Jul 2008
Reputation Points: 279
Solved Threads: 131
 

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

mahavir123
Junior Poster in Training
95 posts since Sep 2010
Reputation Points: 11
Solved Threads: 35
 
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:

zlloyd1
Light Poster
41 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

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

if( isset( $_GET["myname"] ) ){
//code
}
mahavir123
Junior Poster in Training
95 posts since Sep 2010
Reputation Points: 11
Solved Threads: 35
 

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

zlloyd1
Light Poster
41 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

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

Kieran Y5
Junior Poster
137 posts since Aug 2010
Reputation Points: 18
Solved Threads: 18
 

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

zlloyd1
Light Poster
41 posts since Dec 2010
Reputation Points: 10
Solved Threads: 0
 

> 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. :)

diafol
Rhod Gilbert Fan (ardav)
Moderator
7,796 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: