Results 1 to 3 of 3

Thread: Yesterday is FINE, but today always UNDEFINED INDEX, HELP

  1. #1
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Question Yesterday is FINE, but today always UNDEFINED INDEX, HELP

    PHP Code:
    <?php
    if($_POST['myname'])
        echo 
    "My name is ".$_POST['myname'];
    else echo 
    $ret;

    $ret '<html>
        <head>
        <title>Try it</title>
        </head>
        <body>
            <form action="'
    .$_SERVER['PHP_SELF'].'">
                My Name: <input type="text" name="myname"/>
                <input type="submit" name="submit" value="Show it"/>
        </body>
    </html>'
    ;
    ?>
    I have code above, yesterday is fine, but today when i open it in my browser always say:
    Code:
    Notice: Undefined index: myname in C:\xampp\htdocs\try_it.php on line 2
    
    Notice: Undefined variable: ret in C:\xampp\htdocs\try_it.php on line 4
    CAN SOMEBODY TELL ME? thannks so much
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

  2. #2
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    You can't echo something that hasn't been set so we gotta swap the order. You want to check if that array has that value first, and if it does if it has a value. You also should set the method of your form to be sure it will be post.

    PHP Code:
    <?php
    $ret 
    '<html>
        <head>
        <title>Try it</title>
        </head>
        <body>
            <form action="'
    .$_SERVER['PHP_SELF'].'" method="POST">
                My Name: <input type="text" name="myname"/>
                <input type="submit" name="submit" value="Show it"/>
        </body>
    </html>'
    ;
    if(!empty(
    $_POST['myname']))
        echo 
    "My name is ".$_POST['myname'];
    else
    echo 
    $ret;
    ?>
    Last edited by bluewalrus; 07-20-2011 at 02:09 PM. Reason: syntax error, lost a ';'
    Corrections to my coding/thoughts welcome.

  3. #3
    Join Date
    Aug 2008
    Location
    karanganyar, solo, indonesia
    Posts
    161
    Thanks
    4
    Thanked 0 Times in 0 Posts

    Default

    UPS,,, THANKS so much, ,,, it works,,
    <3
    ///////////////////////////////////////////////////
    ///// http://www.mediatutorial.web.id
    ///////////////////////////////////////////////////

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •