All I want to do is to design a form to collect info from users and have a php process it but I kept getting this error shouting undefine variable. Please some 1 check my code and tell me what is beyond my glimps

The form

<form action="process.php" method="post"> 
Your Name: <input type="text" name="name"><br> 
E-mail: <input type="text" name = "email"><br> 
Location: <input type="text" name = "location"><br> 
<input type="submit" value="Submit"> 
</form>

The Processor

<?php 
print "Your name is ". $Name; 
print "<br />"; 
print "You are ". $Age . " years old"; 
print "<br />"; 
$old = 25 + $Age; 
print "In 25 years you will be " . $old . " years old"; 
$Name= ("name")
?>

The Errorgotting when fill the form and press submit
Notice: Undefined variable: Name in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lessons\process.php on line 2
Your name is

Notice: Undefined variable: Age in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lessons\process.php on line 4
You are years old

Notice: Undefined variable: Age in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lessons\process.php on line 6
In 25 years you will be 25 years old

Thanks

Recommended Answers

All 3 Replies

All I want to do is to design a form to collect info from users and have a php process it but I kept getting this error shouting undefine variable. Please some 1 check my code and tell me what is beyond my glimps

The form

<form action="process.php" method="post"> 
Your Name: <input type="text" name="name"><br> 
E-mail: <input type="text" name = "email"><br> 
Location: <input type="text" name = "location"><br> 
<input type="submit" value="Submit"> 
</form>

The Processor

<?php 
print "Your name is ". $Name; 
print "<br />"; 
print "You are ". $Age . " years old"; 
print "<br />"; 
$old = 25 + $Age; 
print "In 25 years you will be " . $old . " years old"; 
$Name= ("name")
?>

The Errorgotting when fill the form and press submit
Notice: Undefined variable: Name in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lessons\process.php on line 2
Your name is

Notice: Undefined variable: Age in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lessons\process.php on line 4
You are years old

Notice: Undefined variable: Age in C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\lessons\process.php on line 6
In 25 years you will be 25 years old

Thanks

you are not setting your varaibles correctly. they dont have any data when you use them. you need to use them like so
$age=15;
right now you use age and it has nothing in it. Also you are doing the same thing with $Name. if your trying to bring this in from your form you will need to reference the name of the input fields like so


$_POST //== the value from <input name='name'>
you need to use the global $_POST and then the field name to directly access that data otherwise you can not.

<?php 
print "Your name is ". $_POST['name']; // follow this with the others
print "<br />"; 
print "You are ". $Age . " years old"; 
print "<br />"; 
$old = 25 + $Age; 
print "In 25 years you will be " . $old . " years old"; 
$Name= ("name")
?>
<?php if($_POST) { // pisspoor validation but this a demo, 
$old = 25 +  $_POST['age'];
echo "Your name is ". $_POST['name']."<br />"
. "You are ".  $_POST['age'] . " years old in ".$_POST['location']."<br />"
. "In 25 years you will be " . $old . " years old";
} else {
echo "<form action='".$_SERVER['PHP_SELF']."' method='post'> "
."Your Name: <input type='text' name='name'><br> "
."age: <input type='text' name = 'age'><br> "
."Location: <input type='text' name = 'location'><br> "
."<input type='submit' value='Submit'> "
."</form>"; } ?>

php forms do not generally require external processing

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.