0
    <body>
    <?php 


    if(trim($_GET["submit"])){

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

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

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

    </body>

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?

3
Contributors
3
Replies
12
Views
2 Years
Discussion Span
Last Post by vampz
1

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";}

Edited by almostbob

0

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'>

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.