Re: Undefined variable

From: Date: Sun, 15 Sep 2002 12:05:13 +0000
Subject: Re: Undefined variable
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-116433@lists.php.net to get a copy of this message
> From: "New B" <res04fg7@verizon.net> > Sent: Sunday, September 15, 2002 7:20 AM > Subject: [PHP] Undefined variable > I am a beginner of PHP, and need help on PHP variable issue: > > I made an HTML form: > > <FORM ACTION="HandleForm.php" METHOD=POST> > First Name <INPUT TYPE=TEXT NAME="FirstName" SIZE=20><BR> > Last Name <INPUT TYPE=TEXT NAME="LastName" SIZE=40><BR> > E-mail Address <INPUT TYPE=TEXT NAME="Email" SIZE=60><BR> > Comments <TEXTAREA NAME="Comments" ROWS=5 COLS=40></TEXTAREA><BR> > <INPUT TYPE=SUBMIT NAME=SUBMIT VALUE="Submit!"> > <INPUT TYPE=RESET NAME=RESET VALUE="Reset"> > </FORM> > ... > > and I try to use a PHP page to retrieve data out: > > ... > <BODY> > <?php > /* This page receives and handles the data generated by "form.html". */ > print "Your first name is $FirstName.<BR>\n"; > print "Your last name is $LastName.<BR>\n"; > print "Your E-mail addres is $Email.<BR>\n"; > print "This is what you had to say:<BR>\n $Comments<BR>\n"; > ?> > </BODY> > ... > > I end up getting error: > > Notice: Undefined variable: FirstName in \HandleForm.php on line 7 > Your first name is . > > Notice: Undefined variable: LastName in \HandleForm.php on line 8 > Your last name is . > > Notice: Undefined variable: Email in \HandleForm.php on line 9 > Your E-mail addres is . > > Notice: Undefined variable: Comments in \HandleForm.php on line 10 > This is what you had to say: Register_globals is now off by default. Learn the new way. Use $_POST['FirstName'] and if inside double quotes wrap the arrary references in curly braces: echo "Your first name is {$_POST['FirstName']}.<BR>\n"; See http://www.php.net/manual/en/language.variables.predefined.php for the complete explaination on register_globals and the new magic globals $_GET, $_POST, etc. Incidentally, you could look at the archives first, since this *is* the most common question these days: http://marc.theaimsgroup.com/?l=php-general&w=2&r=1&s=undefined+variable&q=b

« previous php.general (#116433) next »