Page 1 of 1

SOLVED | variable errors i dont understand

Posted: Thu Sep 08, 2005 5:44 am
by gothica
hi im pretty new here and im also new in php programming. i would just like to as about an error im receiving in php.
btw, ive got php 5.0.4 running under apache 1.3.33

here's the problem:
it's just a simple code im using to test some things..

HTML CODE: info.html

Code: Select all

<html>
<head>
<title>HTML Form</title>
</head>
<body>
<form action = "HandleForm.php" method = post>
First Name <input type = text name = "FirstName" id = "FirstName" size = 20> <br>
Last Name <input type = text name = "LastName" id = "LastName" size = 20> <br>
E-mail Address <input type = text name = "Email" id = "Email" size = 20> <br>
Comments <textarea name = "Comments" id = "Comments" rows = 5 col = 20> </textarea> <br>
<input type = submit name = "submit" value = "submit">
</form>
</body>
</html>
PHP CODE: HandleForm.php

Code: Select all

<?php

print "Your friggin name is $FirstName? <br>";
print "Your friggin email add is $Email. <br>";
print "And your tryin to tell me this: <br> $Comments <br>";

?>
given that info.html will be sending the inputted information and HandleForm.php will be showing the outputs in the screen. For some reason though, im getting this error:

Notice: Undefined variable: FirstName in c:\Program Files\Apache Group\Apache\htdocs\mylessons\HandleForm.php on line 12
Your friggin name is ?

Notice: Undefined variable: Email in c:\Program Files\Apache Group\Apache\htdocs\mylessons\HandleForm.php on line 13
Your friggin email add is .

Notice: Undefined variable: Comments in c:\Program Files\Apache Group\Apache\htdocs\mylessons\HandleForm.php on line 14
And your tryin to tell me this:


am i doing something wrong? please help me out thanks! :)

Posted: Thu Sep 08, 2005 6:16 am
by patrikG
it's not an error. It's a notice (as the text says). What it means is that you have not declared the variables prior to usage.

Advise: use $_POST["FirstName"] etc. instead of the variables you've used.

Posted: Thu Sep 08, 2005 6:16 am
by s.dot
Looks like you have register_globals() off, which is good.

On the page that handles information turn $FirstName into $_POST['FirstName'], $email into $_POST['email'], and comments into $_POST['comments']

Edit: Damn, he beat me.

thanks!!!

Posted: Thu Sep 08, 2005 9:42 am
by gothica
wow thanks a lot! you totally solved my problem. anyways, this is what ive done with the code after the advise you gave me:

Code: Select all

<?php

print "Your friggin name is " . @$_POST['FirstName'] . @$_POST['LastName'] ;
print "<br>";
print "Your friggin email is " . @$_POST['Email'] ;
print "<br>";
print "And your tryin to tell me this: <br>" . @$_POST['Comments'] ;
print "<br>";

?>
:D

Re: thanks!!!

Posted: Thu Sep 08, 2005 9:44 am
by patrikG
gothica wrote:wow thanks a lot! you totally solved my problem. anyways, this is what ive done with the code after the advise you gave me:

Code: Select all

<?php

print "Your friggin name is " . @$_POST['FirstName'] . @$_POST['LastName'] ;
print "<br>";
print "Your friggin email is " . @$_POST['Email'] ;
print "<br>";
print "And your tryin to tell me this: <br>" . @$_POST['Comments'] ;
print "<br>";

?>
:D
The @ in front of $_POST as an error-surpessant is utterly pointless. Apart from that - good that it works.