I am testing this file on my WAMP server localhost and I keep getting an error on line 5... I am trying to check to see if my form data is received when the page loads and if so, it should copy the incoming values to an associative array. If no form data is recieved, it will display the empty form... The problem is my form is not even loading and I believe it is to do with line 5 I just can't seem to figure out how.
Thank you
Here is my PHP/HTML:
<?php
$message = "";
function printform()
{
print <<<EOF
<form>
Customer First Name:<input type='text' name='fname' /><br />
Customer Last Name:<input type='text' name='lname' /><br />
Postal Code:<input type='text' name='postal' /><br />
<input type='submit' value='Send' />
</form>
EOF;
}
function checkdata($mydata)
{
//validate the data
return "error";
}
?>
<html>
<head>
<title>Day 13 Exercise</title>
</head>
<body>
<?php
if (isset($_REQUEST['fname']))
{
//validate data
$data = $_REQUEST;
//print_r($data);
$message = checkdata($data);
if ($message)
{
//there is an error
//redisplay form and display error message
print("<h2 style='color:red'>$message</h2>");
printform();
}
else
{
//enhance later to write data to database
print("Data is valid");
}
}
else
{
//page is loading for the first time
printform();
}
?>
</body>
</html>
Try getting rid of the two spaces at the end of the line after EOF;
Usually spaces at the end of the line don't matter in PHP, but the <<< syntax is very picky about white space.