Hello Daniweb posters. I have a code that is supposed to make a sign up sheet for a web page. Problem is, the code does not work. When I run the code it gives me:
syntax error, unexpected T_PRINT in line 15.
I know there is something wrong with the heredoc syntax I have, but I do not know why.
<?php
if ($_POST["page"] == "confirm")
{
confirmPage ();
}
else
{
orderForm();
}
function orderForm()
{
$script = $_SERVER['PHP_SELF'];
print <<<TOP
<html>
<head>
<title> Online Sign Up </title>
</head>
<body>
<h3> Online Sign Up</h3>
<form method = "post" action = "$script">
<p>
<table border = "2" width="400">
<th>Time</th>
<th>Name</th>
TOP;
$schedule = getSchedule();
for($i = 0; $i<count($schedule); $i+=2)
{
$index = $i+1;
print("<tr>");
print("<td> <center> $schedule[$i] </center> </td>");
if($schedule[$index]=="")
{
print("<td> <center> <input type = \"text\" name = \"$index\" size = \"30\"> </center> </td>");
}
else
{
print("<td> <center> $schedule[$index] </center> </td>");
}
print("</tr>");
}
print <<<BOTTOM
</table>
<input type = "hidden" name = "page" value = "confirm" />
</p>
<p>
<input type = "submit" value = "Submit" />
</p>
</form>
</body>
</html>
BOTTOM;
}
function getSchedule()
{
$lines = file("./signup.txt", FILE_IGNORE_NEW_LINES);
$schedule = array();
foreach ($lines as $line_num => $line)
{
$schedule[$line_num] = $line;
}
return $schedule;
}
function setSchedule($schedule)
{
$file = fopen ("./signup.txt", w);
for($i=0; $i<count($schedule); $i++)
{
fwrite($file, $schedule[$i]."\n");
}
fclose($file);
}
function confirmPage()
{
$script = $_SERVER['PHP_SELF'];
$schedule = getSchedule();
print <<<TOP
<html>
<head>
<title> Sign Up </title>
</head>
<body>
<h2> Confirmation </h2>
<p>
TOP;
for($i=1; $i<=count($schedule); $i+=2)
{
if($_POST[$i])
{
if($schedule[$i] == "")
{
$index = $i-1;
$schedule[$i] = $_POST[$i];
print("$schedule[$i] is now scheduled for $schedule[$index] \n");
}
else
{
print <<<ERROR
Unable to add $schedule[$i] to $schedule[$index]. Please enter another time.
<form>
<input type = "hidden" name = "page" value = "" />
<input type = "submit" value = "Return" />
</form>
ERROR;
}
}
}
setSchedule($schedule);
print <<<BOTTOM
</p>
</body>
</html>
BOTTOM;
}
?>