Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post

    Post "Undefined index:" in form.

    Good night to you all,

    I have a kind of shoutbox, flat file based, which give me an error :
    "Undefined index:"

    I know what this mean, but I don't see my mistakes can somebody help me ?


    PHP Code:

    <?php

    if ($_POST['nameq'] != "" && $_POST['messageq'] != "")
    {
    $nom $_POST["nameq"];
    $nomcorr substr($nom0, -9);
    $messageq $_POST["messageq"];



    $File date('Y')."/".date('m')."/".date('d')."/messages.html";
    $Handle fopen($File'w+');

    $Data "<b class=\"red\">$nom</b>";
    $Data.= $messageq;
    $Data.= "<br/></br/>";
    fwrite($Handle$Data);

    fclose($Handle);


    }

    ?>




    <form action="" method="post">
    <input type="text" name="nameq" value="<? echo $_SESSION['Name'];?>"/>
    <?
    echo "<select  name=\"COLOUR_CHOICE\" id=\"COLOUR_CHOICE\">";

    $colourArray = array("000000""cccc99""FFFFFF""0000FF");
    for (
    $i 0$i count($colourArray); $i++)
    {
        
    $selected = ($colourArray[$i] == trim($_POST['COLOUR_CHOICE'])) ? 'selected="selected"' '';
        echo 
    '<option value="' $colourArray[$i] . '"' $selected  ' . id="opt' $colourArray[$i] . '">#' $colourArray[$i] . '</option>';
    }  
    echo 
    "</select>";
    ?>

    <textarea name="messageq"></textarea>
    <input type="submit" name="Envoyer !!!" value="post"/>
    </form>


    Thanks!
    Have a good one !

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    It's due to the usage any uninitialised variables somewhere is the page. Check the line number along with the error!
    Also see http://in2.php.net/error_reporting , if you really want to suppress this notice.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Feb 2006
    Posts
    262
    Thanks
    23
    Thanked 1 Time in 1 Post
    Bingo, I had to use isset :


    if (isset($_POST['nameq'])) {


    Thanks !

  • #4
    Senior Coder
    Join Date
    Jan 2007
    Posts
    1,648
    Thanks
    1
    Thanked 58 Times in 54 Posts
    Quote Originally Posted by abduraooft View Post
    if you really want to suppress this notice.
    This is a really bad idea. You don't want to ever suppress warnings/errors.


  •  

    Posting Permissions

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