Undefined Index

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
bubberz
Forum Newbie
Posts: 14
Joined: Wed Jul 13, 2005 12:05 pm

Undefined Index

Post by bubberz »

I've got a page a user sees if they're a new user. They enter an email and password.

If the "Check New Username" behavior allows the entry to continue, the new user will enter more information about themselves.

I'm trying to use the Email and password for the first two text fields in the next form via Bindings / Form Variable, but get the following for both these fields:

Undefined index: Email in <b>C:\htdocs\NewSubInfo.php

The HTML is:

value="<?php echo $_POST['Email']; ?>"

This should be pretty simple, but I'm not too sure what I'm doing wrong.

Thanks!
jmut
Forum Regular
Posts: 945
Joined: Tue Jul 05, 2005 3:54 am
Location: Sofia, Bulgaria
Contact:

Post by jmut »

To have something in $_POST variable, hence, not having undefined index you should first submit a form.
Clearly the first time the page is accessed no form is submitted.


You should check if there is something in $_POST.

Code: Select all

if (isset($_POST['field_name'])) {
  $field_name = $_POST['field_name'];   //will do this if you have posted form
} else {
  $field_name = 'default value';  //if you do not have post there will be default value. For example the first time you access the page(before submiting post.)
}

//...use $field_name somewhere.
Have in mind that you should validade each POST as dada most probably comes from user interaction and we all know users are not to be trusted.
Post Reply