...

View Full Version : Im having problems with my php code. Can ne1 tell me whats wrong?



l3vi
03-09-2003, 03:52 PM
Im just starting out w/ php and im trying to do this code as a test, but I cant get it to work. It will always say something like this: Notice: Undefined variable: Comments in c:\program files\apache group\apache\htdocs\infor.php on line 6. Can anyone help me out with this? BTW, here is the code I used for the Form...

<form action="infor.php" method=POST>
First Name: <input type=Text name="FirstName"><br>
Last Name: <input type=Text name="LastName"><br>
Email: <input type=Text name="Email"><br>
Comments: <textarea name="Comments" rows=10 cols=50></textarea><br>
<input type="submit">
</form>

and here is the code I used for the PHP script.


<?
print("Your first name is $FirstName");
print("Your last name is $LastName");
print("Your Email is $Email");
print("This is what you had to say: $Comments");
?>

<form action="infor.php" method=POST>
First Name: <input type=Text name="FirstName"><br>
Last Name: <input type=Text name="LastName"><br>
Email: <input type=Text name="Email"><br>
Comments: <textarea name="Comments" rows=10 cols=50></textarea><br>
<input type="submit">
</form>

Thanx in advance!:thumbsup:

Spookster
03-09-2003, 04:19 PM
That because you are trying to print out variables that do not yet have values. This will happen when you try to load the page before the form fields are filled out. What you need to do is either put the php code in another page and submit the form to that page or put a flag variable in the code to check to see if the form has been submitted yet or not. Something like


if(isset("submit")){
print $Comments;
}
else{
//do nothing
}

l3vi
03-09-2003, 04:54 PM
:confused:i do have two seperate pages. One page is info.html then it goes to infor.php.

Íkii
03-09-2003, 06:41 PM
to learn syntax referencing, put this in your receiving page

foreach($_POST as $var=$val)
{
echo '$_POST[\\'' .$var. '\\'] = ' .$val .'<br />';
}


you should access posted/getted/cookieed/sessioned/servered vars with the array definition followed by the variable name - eg $_SESSION['blat']



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum