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;
  }
?>

Recommended Answers

All 4 Replies

Can you show the full, unmarked code please?

From the looks of it your code is marked to tell us where the errors are, but that does not help us in terms of what TOP and BOTTOM mean.

If this is your actual code, I suggest you look heavily into PHP tutorials.

Use the PHP delimiters before starting HTML tags.Change your code as to

<?php
 if ($_POST["page"] == "confirm")
 {
   confirmPage ();
 }
 else
 {
    orderForm();
 }

 function orderForm()
 {
  $script = $_SERVER['PHP_SELF'];
    ?>
	  <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>

<?php
    $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>");
    }
 ?>
  </table>
  <input type = "hidden" name = "page" value = "confirm" />
  </p>
  <p>
  <input type = "submit" value = "Submit" />
  </p>
  </form>
  </body>
  </html>
<?php
  }

  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();
   ?>
    <html>
    <head>
    <title> Sign Up </title>
    </head>
    <body>
    <h2> Confirmation </h2>
    <p>
<?php
    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
            {
               
               echo " 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>
<?php
            }
        }
    }
    setSchedule($schedule);

  ?>
    </p>
    </body>
    </html>
<?php
  }
?>

remove the

print()

and change it into

echo()

in line 15.

print <<<TOP
<html> ... </html>

to

echo "
<html>... </html>";

Okay, I will do the above decade.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.