1.

Solve : php help?

Answer»

$Fname = $_POST["Fname"];
$Lname = $_POST["Lname"];
$gender = $_POST["gender"];
$food = $_POST["food"];
$QUOTE = $_POST["quote"];
$education = $_POST["education"];
$TofD = $_POST["TofD"];
if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>


Personal INFO



First Name:

Last Name:

Gender:

Male:

Female:

PLEASE choose type of residence:

Steak:

Pizza:

Chicken:

Enter your favorite quote!

Select a Level of Education:


Jr.High
HighSchool
College

Select your favorite time of day:


Morning
Day
Night



} else {
echo "Hello, ".$Fname." ".$Lname.".
";
echo "You are ".$gender.", and you like ";
foreach ($food as $f) {
echo $f."
";
}
echo "".$quote."
";
echo "You're favorite time is ".$TofD.", and you PASSED ".$education."!
";
}
?>




...I'm a beginner in php programming, this is the 1st sample that I copied from http://www.tizag.com/phpT/examples/formfinale.php
but when I try to see the outputt using XAMPP. there is an error and i can't figure it out what is missing? thanks in advanceWhat error are you getting from XAMPP, that would be helpful to know!Parse error: syntax error, unexpected end of file in the LINE 49added php before else...
now the error is
undefined index on line 2 to 8

here's the code

$Fname = trim ($_POST["Fname"]);
$Lname = trim ($_POST["Lname"]);
$gender = trim ($_POST["gender"]);
$food = trim ($_POST["food"]);
$quote = trim ($_POST["quote"]);
$education = trim ($_POST["education"]);
$TofD = trim ($_POST["TofD"]);
if (!isset($_POST['submit'])) { // if page is not submitted to itself echo the form
?>


Personal INFO



First Name:

Last Name:

Gender:

Male:

Female:

Please choose type of residence:

Steak:

Pizza:

Chicken:

Enter your favorite quote!

Select a Level of Education:


Jr.High
HighSchool
College

Select your favorite time of day:


Morning
Day
Night



added php
} else
{
echo "Hello, ".$Fname." ".$Lname.".
";
echo "You are ".$gender.", and you like ";
foreach ($food as $f) {
echo $f."
";
}
echo "".$quote."
";
echo "You're favorite time is ".$TofD.", and you passed ".$education."!
";
}
?>Your issue is that you are trying to access elements of the $_POST array when the form hasn't been submitted. You need to move the first block of lines:
Code: [Select]$Fname = trim ($_POST["Fname"]);
$Lname = trim ($_POST["Lname"]);
$gender = trim ($_POST["gender"]);
$food = trim ($_POST["food"]);
$quote = trim ($_POST["quote"]);
$education = trim ($_POST["education"]);
$TofD = trim ($_POST["TofD"]);To be inside your else statement so these variables are only created if the form has actually been submitted. thanks much!



Discussion

No Comment Found