heredoc not acting correctly [SOLVED]

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Stefko
Forum Newbie
Posts: 5
Joined: Sat Apr 07, 2007 2:30 pm

heredoc not acting correctly [SOLVED]

Post 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++;
}
?>
Last edited by Stefko on Sat Apr 07, 2007 3:07 pm, edited 4 times in total.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post by aaronhall »

What indicates to you that it isn't recognizing the end tag? A parse error maybe?
Stefko
Forum Newbie
Posts: 5
Joined: Sat Apr 07, 2007 2:30 pm

Post by Stefko »

Image
Stefko
Forum Newbie
Posts: 5
Joined: Sat Apr 07, 2007 2:30 pm

Post 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]
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

It could have something to do with the double underscores you are using. Change the name to something different.
Stefko
Forum Newbie
Posts: 5
Joined: Sat Apr 07, 2007 2:30 pm

Post by Stefko »

been there, done that!

This one has me pulling my hair out!
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

I see PHP's short open tag. Turn it into a standard open tag. <? = <?php
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

.. Also, make sure that the heredoc ending tag is the FIRST THING on the line. It cannot be indented at all.
User avatar
aaronhall
DevNet Resident
Posts: 1040
Joined: Tue Aug 13, 2002 5:10 pm
Location: Back in Phoenix, missing the microbrews
Contact:

Post 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.
Last edited by aaronhall on Sat Apr 07, 2007 2:55 pm, edited 1 time in total.
Stefko
Forum Newbie
Posts: 5
Joined: Sat Apr 07, 2007 2:30 pm

Post 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!
nickvd
DevNet Resident
Posts: 1027
Joined: Thu Mar 10, 2005 5:27 pm
Location: Southern Ontario
Contact:

Post by nickvd »

Glad I could help!
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post 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.
Post Reply