SOLVED | variable errors i dont understand

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
gothica
Forum Newbie
Posts: 15
Joined: Thu Sep 08, 2005 5:24 am

SOLVED | variable errors i dont understand

Post 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! :)
Last edited by gothica on Thu Sep 08, 2005 10:07 am, edited 1 time in total.
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post 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.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post 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.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
gothica
Forum Newbie
Posts: 15
Joined: Thu Sep 08, 2005 5:24 am

thanks!!!

Post 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
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Re: thanks!!!

Post 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.
Post Reply