Parse error: syntax error, unexpected $end

so i was making this can you guess this number program for practice but unfortunetly no matter what i do i keep getting a “Parse error: syntax error, unexpected $end in document on the last line”, everywhere i look says to use <?php…?> instead of just <?..?> but i do and as far as i can tell all my brackets and qutations are correct, so i have no clue why im getting this error, please help.

heres the code:

<?php
$randNumber = $_POST['randNumber'];
$guess = $_POST['guess'];
if ($randNumber > $guess){
	print "<h1>Too High, try again </h1> <br /> \
";
	print <<<HERE
  <form action="numbcheck.php" method="post">
  <input name="guess" type="text" id="guess" value="" size="25" maxlength="4" />
  <input type="hidden" value="$randNumber" id="randNumber" name="randNumber" />
  <br />
  <input type="submit" value="Submit Guess" name="subButton"  />
  </form>
  HERE;
 } else if ($randNumber < $guess){
	  print "<h1> Too Low, Try again</h1><br /> \
");
	  print <<<HERE
   <form action="numbcheck.php" method="post">
   <input name="guess" type="text" id="guess" value="" size="25" maxlength="4" />
   <input type="hidden" value="$randNumber" id="randNumber" name="randNumber" />
   <br />
   <input type="submit" value="Submit Guess" name="subButton"  />
   </form>
  	HERE;
  } else if ($randNumber == $guess){
  print ("<h1>CORRECT!!!</h1> <br /> \
");
  print "<a href='number.php'>Click here to play again</a>";
 } else {
	  print "<h1>Your Crazy</h1>";
 } //end if
?>

You haven’t closed off the heredoc content. The end tag must not be indented for it to be correctly interpreted.

i added quattion marks to the here, but it didnt work, i think im a little confused with what you mean

There are two lines which close heredoc blocks:

HERE;
Them two lines can’t be indented at all. Have a read of the part of the manual which deals with heredoc here.

[QUOTE=maxdream01;4877887]

<?php
$randNumber = $_POST['randNumber'];
$guess = $_POST['guess'];
if ($randNumber > $guess){
	print "<h1>Too High, try again </h1> <br /> \
";
	print <<<HERE
  <form action="numbcheck.php" method="post">
  <input name="guess" type="text" id="guess" value="" size="25" maxlength="4" />
  <input type="hidden" value="$randNumber" id="randNumber" name="randNumber" />
  <br />
  <input type="submit" value="Submit Guess" name="subButton"  />
  </form>

HERE;// <<== Must not be indented

 } else if ($randNumber < $guess){
	  print "<h1> Too Low, Try again</h1><br /> \
");
	  print <<<HERE
   <form action="numbcheck.php" method="post">
   <input name="guess" type="text" id="guess" value="" size="25" maxlength="4" />
   <input type="hidden" value="$randNumber" id="randNumber" name="randNumber" />
   <br />
   <input type="submit" value="Submit Guess" name="subButton"  />
   </form>

HERE; // <= Must be at the left, no indents or anything

Off Topic:

HEREDOC/NOWDOC sucks for this very reason :slight_smile:

Rubbish!

I use it quite a lot in some of my php files for my CMS that i’m working on. It makes life a lot easier in some situations. I’ll agree it’s not useful for everything but it does have its place. Like most inventions, someone at php.net clearly came up with it to solve a problem and that problem is almost certainly going to be one that others face at some point.

He could do without heredoc completely, but there can be OOP issues that get in the way of such things.


<?php
$randNumber = $_POST['randNumber'];
$guess = $_POST['guess'];
if ($randNumber > $guess){
?>
  <h1>Too High, try again </h1> <br />
  <form action="numbcheck.php" method="post">
  <input name="guess" type="text" id="guess" value="" size="25" maxlength="4" />
  <input type="hidden" value="$randNumber" id="randNumber" name="randNumber" />
  <br />
  <input type="submit" value="Submit Guess" name="subButton"  />
  </form>
<?php
 } else if ($randNumber < $guess){
?>
   <h1> Too Low, Try again</h1><br />
   <form action="numbcheck.php" method="post">
   <input name="guess" type="text" id="guess" value="" size="25" maxlength="4" />
   <input type="hidden" value="$randNumber" id="randNumber" name="randNumber" />
   <br />
   <input type="submit" value="Submit Guess" name="subButton"  />
   </form>
<?php
  } else if ($randNumber == $guess){
      print ("<h1>CORRECT!!!</h1> <br /> \
");
      print "<a href='number.php'>Click here to play again</a>";
 } else {
      print "<h1>Your Crazy</h1>";
 } //end if
?>

ok thanks it works now, also now that you mention that i remember reading that about heredocs somewhere, but i wish the error would have just told me it was on that line and i might have been able to guess the problem, anyway thanks