Page 1 of 1

heredoc not acting correctly [SOLVED]

Posted: Sat Apr 07, 2007 2:34 pm
by Stefko
PHP5 does not reconize the heredoc end tag.

And the end tag is to the far left, and no code is above or below the end tag?
Any ideas why?

Code: Select all

<?

$letter = array("a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m",
    "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "A", "B", "C",
    "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S",
    "T", "U", "V", "W", "X", "Y", "Z", "1", "2", "3", "4", "5", "6", "7", "8", "9",
    "0");
$color1 = "#e0e0e0";
$color2 = "white";
$result = mysql_query("SELECT * FROM loginphp ORDER BY id") or die(mysql_error());
$i = 0;
$counter = 0;
while ($row = mysql_fetch_array($result))
{
    $Uname = $row['Uname'];
    $id = $row['id'];
    $password = $row['Pword'];
    $row_color = ($i % 2) ? $color1:$color2;
    if ($id == 1)
    {
        $status = " DISABLED";
        $level = "YES";
    }
    else
    {
        $status = "";
        $level = "NO";
    }

    $val = str_replace($letter, "*", $password);

$HTML = <<<__html__

<form name="update" action="EditUser.php">
<input type="hidden" name="USER" value="$Uname">
<tr>
<td align="center"  bgcolor="$row_color">
<input type="radio" name="ACTION" value="edit"$status>
</td>
<td align="center"  bgcolor="$row_color">
<input type="radio" name="ACTION" value="delete"$status>
</td>
<td align="center"  bgcolor="$row_color">$Uname</td>
<td align="center"  bgcolor="$row_color">$val</td>
<td align="center"  bgcolor="$row_color">$level</td>
<td align="center"  bgcolor="$row_color">
<input type="image" src="../images/new/submit.gif" value="SUBMIT">
</form>
</td>
</tr>

__html__;

echo $HTML;

    $i++;
    $counter++;
}
?>

Posted: Sat Apr 07, 2007 2:40 pm
by aaronhall
What indicates to you that it isn't recognizing the end tag? A parse error maybe?

Posted: Sat Apr 07, 2007 2:45 pm
by Stefko
Image

Posted: Sat Apr 07, 2007 2:48 pm
by Stefko
No errors, just a simple PHP Notice, noting serious!

Code: Select all

[Sat Apr  7 16:20:00 2007] [error] PHP Notice:  A session had already been started - ignoring session_start() in /www/xxxxxxx/htdocs/cart/admin/top.php on line 9
[Sat Apr  7 16:20:00 2007] [error] PHP Notice:  Constant AUTH_VALID already defined in /www/xxxxxxxx/htdocs/cart/admin/Users.php on line 3
[/quote]

Posted: Sat Apr 07, 2007 2:51 pm
by nickvd
It could have something to do with the double underscores you are using. Change the name to something different.

Posted: Sat Apr 07, 2007 2:52 pm
by Stefko
been there, done that!

This one has me pulling my hair out!

Posted: Sat Apr 07, 2007 2:53 pm
by nickvd
I see PHP's short open tag. Turn it into a standard open tag. <? = <?php

Posted: Sat Apr 07, 2007 2:54 pm
by nickvd
.. Also, make sure that the heredoc ending tag is the FIRST THING on the line. It cannot be indented at all.

Posted: Sat Apr 07, 2007 2:54 pm
by aaronhall
I wonder how it's getting to the browser if it's not being echoed.... hmmm, anyway, I'd stay away from the double underscores too. Try something like HTML_BLOCK.

Posted: Sat Apr 07, 2007 2:55 pm
by Stefko
Sweet, I missed that one, was looking for everthing else, thanks a heep!

It was the PHP shorthand, added php to <? and it works!

Posted: Sat Apr 07, 2007 2:59 pm
by nickvd
Glad I could help!

Posted: Sun Apr 08, 2007 3:29 pm
by RobertGonzalez
Tell you what, it would be nice for everyone to start using regular opening PHP tags nowadays. That little bugger gas bitten more than one developer around here in the last few weeks.