Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Undefined index error/notice in text box ... kindly help me

Status
Not open for further replies.

amir4oracle

Programmer
Nov 3, 2004
46
CA
The following Code is giving the following Error/notice "Undefined index" in the text box f_name ... kindly help me:

-----------------------------------------------------------------------------

CODE:


1 <?
2
3 if (isset ($_POST['submit']))
4 {
5 $message = NULL;
6
7 if (strlen ($_POST['f_name']) > 0)
8 {
9 $f_name = TRUE;
10 }
11 else
12 {
13 $f_name = FALSE;
14 $message = '<p>You forgot to enter name.</p>';
15 }
16 }
17
18 ?>
19
20 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
21
22 Name: <input type="text" name="f_name" size="20" maxlength="40" value="<?php echo ($_POST ['f_name']); ?>" />
23
24 <input type="submit" name="submit" value="Submit Information"/>
25
26 </form>


-----------------------------------------------------------------------------

Error/notice:


<br /><b>Notice</b>: Undefined index: f_name in <b>c:\inetpub\ on line <b>22</b><br />
 
That's a pretty straightforward error.

At the time the variable is references, $_POST['f_name'] does not exist.

One line in the script:

if (isset ($_POST['submit']))

implies to me that this script expects that sometimes there will be nothing in $_POST. But the line that uses $_POST['f_name'] assumes the variable will always be there.

Want the best answers? Ask the best questions!

TANSTAAFL!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top