I’m new in PHP, but I have programmed before using C, C++. I’ve started the book above by Kevin Yank. So far everything was going smooth until the following example, which doesn’t work the way I expected. The program works correctly when you enter your name or “Kevin Yank” into the form. However when you live the form empty it returns this:
“Welcome to our web site, !”
instead of form.html.php
Please help to solve this puzzle, Thanks.
aaalexan
1)index.php
<?php
if (!isset($_REQUEST[‘firstname’]))
{
include ‘form.html.php’;
}
else
{
$firstname = $_REQUEST[‘firstname’];
$lastname = $_REQUEST[‘lastname’];
if ($firstname == ‘Kevin’ and $lastname == ‘Yank’)
{
$output = ‘Welcome, oh glorious leader!’;
}
else
{
$output = 'Welcome to our web site, ’ .
htmlspecialchars($firstname, ENT_QUOTES, ‘UTF-8’) . ’ ’ .
htmlspecialchars($lastname, ENT_QUOTES, ‘UTF-8’) . ‘!’;
}
include ‘welcome.html.php’;
}
?>
2)wecome.html.php
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml” xml:lang=“en” lang=“en”>
<head>
<title>Form Example</title>
<meta http-equiv=“content-type”
content=“text/html; charset=utf-8”/>
</head>
<body>
<p>
<?php echo $output; ?>
</p>
</body>
</html>
3)form.html.php
<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Strict//EN”
“http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd”>
<html xmlns=“http://www.w3.org/1999/xhtml” xml:lang=“en” lang=“en”>
<head>
<title>Form Example</title>
<meta http-equiv=“content-type”
content=“text/html; charset=utf-8”/>
</head>
<body>
<form action=“” method=“post”>
<div><label for=“firstname”>First name:
<input type=“text” name=“firstname” id=“firstname”/></label>
</div>
<div><label for=“lastname”>Last name:
<input type=“text” name=“lastname” id=“lastname”/></label>
</div>
<div><input type=“submit” value=“GO”/></div>
</form>
</body>
</html>