echo "your name is".$_GET['uname'];
        else {
        echo"please enter your name";

    <label for="uname">Name</label>
    <input type="text" name="uname" />

    <input type="submit" name="submit" value="Submit" />


hello, i'm new to php watching some tuts and trying to learn...my proble is when i load this code in browser then first time i get an error of undefined index but when i press submit button all goes well the error removes and if condition works properly..my problem is why i'm getting error of undefined index on page load?? any option to resolve this?

Recommended Answers

All 3 Replies

the first time you load the page, $_GET[] is empty, not populated until the form is submitted,, code not checked count {braces}

if(isset($_GET['submit'])){if($_GET["uname"]){echo "your name  is".$_GET['uname'];}}
  else {echo"please enter your name";}

I agree with @almostbob but also your <form> is empty where you should pass an action and a method for example <form action='nameofpagehere.php' method='get'>

bundle of thanks i resolved it by your way....@almostbob.

Be a part of the DaniWeb community

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