This is my first real attempt at coming to StackExchange and I wanted my question to be as relevant as possible. Basically, I am following along in the O'Reilly book to Learn PHP, MySQL, Javascript, etc. and I'm a bit stuck on Chapter 16's authentication protocol. Basically the author wants us to just put the CSS and JS in the echo <<<_END statements, I'm trying to put it so they can still be kept separate in their external file.
My problem is, when I load the PHP file, absolutely nothing comes up. Not even a title. I was concerned this might have something to do with the fact that I'm running WebMatrix and an IIS Express server for development, but I have been able to run other, much smaller echo <<<_END statements fine when I went to test them.
Below is the code, if anyone has input I would be very grateful.
<?php
$firstname = $lastname = $username = $password = $age = $email = "";
if (isset($_POST['firstname']))
{
$firstname = fix_string($_POST['firstname']);
}
if (isset($_POST['lastname']))
{
$lastname = fix_string($_POST['lastname']);
}
if (isset($_POST['username']))
{
$username = fix_string($_POST['username']);
}
if (isset($_POST['password']))
{
$password = fix_string($_POST['password']);
}
if (isset($_POST['age']))
{
$age = fix_string($_POST['age']);
}
if (isset($_POST['email']))
{
$email = fix_string($_POST['email']);
}
$fail = valide_firstname($firstname);
$fail .= valide_lastname($lastname);
$fail .= valide_username($username);
$fail .= valide_password($password);
$fail .= valide_age($age);
$fail .= valide_email($email);
echo <<<_END
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>An Example Form</title>
<link rel="stylesheet" type="text/css" href="StyleSheet.css>
</head>
_END;
if ($fail = "")
{
echo "<body>Form data succesffully validated: $firstname, $lastname, $username, $password, $age, $email.</body></html>";
//database entry field
exit;
}
echo <<<_END
<body>
<table class="signup" border="0" cellpadding="2"
cellspacing="5" bgcolor="#eeeeee">
<th colspan="2" align="center">Signup Form</th>
<tr><td colspan="2">Sorry, the following errors were found<br />
in your form: <p><font color=red size=1><i>$fail</i></font></p>
</td></tr>
<form method="post" action = "adduser.php"
onSubmit = "return validate(this)">
<tr><td>First name</td><td><input type ="text" maxlength = "32"
name = "firstname" value = "$firstname" /></td></tr>
<tr><td>Last name</td><td><input type ="text" maxlength = "32"
name = "lastname" value = "$lastname" /></td></tr>
<tr><td>Username</td><td><input type ="text" maxlength = "16"
name = "username" value = "$username" /></td></tr>
<tr><td>Password</td><td><input type ="text" maxlength = "12"
name = "password" value = "$password" /></td></tr>
<tr><td>Age</td><td><input type ="text" maxlength = "3"
name = "age" value = "$age" /></td></tr>
<tr><td>Email</td><td><input type ="text" maxlength = "64"
name = "email" value = "$email" /></td></tr>
<tr><td colspan = "2" align = "center"><input type = "submit" value = "Signup" /></td></tr></form></table>
<script type="text/javascript" src="validate.js"></script>
</body>
</html>
_END;
function validate_fistname($field){
if ($field == "") return "No First Name was entered <br/>";
}
function validate_lastname($field){
if ($field == "") return "No Last Name was entered <br/>";
}
function validate_username($field){
if ($field == "") return "No Username was enterted <br/>";
else if (strlen($field) < 5) return "Usernames must be at least 5 characters long <br/>";
else if (preg_match("/[\W]/", $field)) return "Only letters, numbers, - and _ is usernames<br/>";
return "";
}
function validate_password($field){
if ($field =="") return "No Password was entered <br/>";
else if (strlen($field) < 6) return "Passwords must be at least 6 characters in length <br/>";
else if (!preg_match("/[a-z]/", $field) ||
!preg_match("/[A-Z]/", $field) ||
!preg_match("/[\d]/", $field))
return "Passwords require one upper case, one lower case, and one number<br/>";
return "";
}
function validate_age($field) {
if ($field == "") return "No Age was entered<br />";
else if ($field < 18 || $field > 110)
return "Age must be between 18 and 110<br />";
return "";
}
function validate_email($field) {
if ($field == "") return "No Email was entered<br />";
else if (!((strpos($field, ".") > 0) &&
(strpos($field, "@") > 0)) ||
preg_match("/[^a-zA-Z0-9.@_-]/", $field))
return "The Email address is invalid<br />";
return "";
}
function fix_string($string) {
if (get_magic_quotes_gpc()) $string = stripcslashes ($string);
return htmlentities ($string);
}
?>