1

When I try to echo most of XTHML tags inside a PHP loop which one echo's data from a MySQL it just shows text in browser. I'm running XAMPP Control Panel with Apache and MySQL for tests.

CODE:

echo "<textarea readonly>";
while ($wiersz = mysql_fetch_array($sql_wynik_zapytania)) 
{
echo "   ".$wiersz['NICK'].":\n";
echo $wiersz['KOMENT']."\n"."<hr />"."\n";
}
echo "</textarea>";

The results in browser:

   NICK:
a
<hr />
   NICK:
asdaa
<hr />
   pallluch:
cccc

"a" "asdaa" "cccc" are just random texts added to table in databse for tests.

Echo works perfectly fine with <textarea>, but <hr> doesn't seems to.

Can anyone help?

Michael Benjamin
  • 346,931
  • 104
  • 581
  • 701
PAlllUCH
  • 13
  • 4
  • **Warning**: You are using [an **obsolete** database API](http://stackoverflow.com/q/12859942/19068) which has been **removed** entirely from the latest version of PHP. You should use a [modern replacement](http://php.net/manual/en/mysqlinfo.api.choosing.php). – Quentin Jun 11 '16 at 11:20
  • 1
    Your document isn't XHTML by the way. If it was, the browser would complain loudly about the error in the start tag. – Mr Lister Jun 11 '16 at 11:22

1 Answers1

0

A textarea element can't contain anything other than plain text.

You are writing invalid HTML and the browser is trying to recover by treating the < character as plain text instead of the start of a tag.

It looks like you aren't using the textarea to accept user input anyway (you've made it readonly). Don't use a textarea element here. You probably want to use <pre> instead.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Oh, this works, thanks. I know how to make it scrollable, but how can i format '
    '  to show for example 20 letters in line and then go to next one?
    – PAlllUCH Jun 11 '16 at 11:32