#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Posts
    14
    Rep Power
    0

    Exclamation "Undefined index" message as submitting a form : why?


    PHP Code:
    <?PHP
    if (isset($_POST['Submit1'])) {
    $username $_POST['username'];
    if (
    $username == "key") {
    print (
    "in");
    }
    else {
    print (
    "out");
    }
    }
    ?>

    Why do I receive the message below as I click submit :
    Notice: Undefined index: username in C:\wamp\www\basic_form.php on line 8.
    It does not matter whether I type the correct word or not , the result is the same, it prints "out" and the message.
    What´s wrong .
    Thank you.

    ps .: line 8 on dreamweaver is $username = $_POST['username'];
    Last edited by Ron Wolpa; September 5th, 2013 at 10:02 AM. Reason: mispelled word
  2. #2
  3. No Profile Picture
    Contributing User
    Devshed Regular (2000 - 2499 posts)

    Join Date
    Mar 2006
    Posts
    2,400
    Rep Power
    1688
    I do not know php, but that would, to me, indicate that the $_POST array did not contain an index named 'username' - what do you see if you do a print_r($_POST)?
    The moon on the one hand, the dawn on the other:
    The moon is my sister, the dawn is my brother.
    The moon on my left and the dawn on my right.
    My brother, good morning: my sister, good night.
    -- Hilaire Belloc
  4. #3
  5. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,918
    Rep Power
    1045
    Hi,

    let me guess: You named the field not "username" but "user_name" or "Username" or "UserName" -- or something with "1" at the end.
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Posts
    14
    Rep Power
    0
    Originally Posted by Jacques1
    Hi, let me guess: You named the field not "username" but "user_name" or "Username" or "UserName" -- or something with "1" at the end.
    <FORM NAME ="form1" METHOD ="POST" ACTION = "basic_form.php">
    <INPUT TYPE = "TEXT" VALUE ="username">
    <INPUT TYPE = "Submit" Name = "Submit1" VALUE = "Login">
    </FORM>
    I´ve pasted the form code. Nope , it is correct : username.
  8. #5
  9. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,918
    Rep Power
    1045
    That's the value, not the name.
    The 6 worst sins of securityHow to (properly) access a MySQL database with PHP

    Why can’t I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  10. #6
  11. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2007
    Posts
    14
    Rep Power
    0
    Originally Posted by Jacques1
    That's the value, not the name.
    That´s right sir , I just added name and it worked.
    <INPUT TYPE = "TEXT" name="username" VALUE ="username">
    I just hope to be able to learn php.
    Thank you very much.
  12. #7
  13. Sarcky
    Devshed Supreme Being (6500+ posts)

    Join Date
    Oct 2006
    Location
    Pennsylvania, USA
    Posts
    10,692
    Rep Power
    6351
    This was actually a problem with your HTML, not your PHP. They are unrelated languages and (when combined with SQL and JavaScript) make up a PART of a full website.

    The new user guide has more.
    HEY! YOU! Read the New User Guide and Forum Rules

    "They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin

    "The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002

    Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.

IMN logo majestic logo threadwatch logo seochat tools logo