need help w/ outputting to a textarea

need help w/ outputting to a textarea

am 02.05.2006 16:22:02 von Jeff Brady

I have a pretty simple mysql db, and have no problems echoing the data
via php.

My problem is with trying to print the data to a textarea (on a form, so
the data can be edited)

My form is pretty simple .. text box for field1, textbox for field2, and
a textarea for field3 (because field3 can contain a few paragraphs of text)

the main part of the page looks like this:
================================================
<...connect to db stuff>

$id = $_GET['id']; //grabs ID value from URL
$query="SELECT * FROM news WHERE idx = $id";
$result=mysql_query($query) or die("MySQL Error:
".mysql_error()."\n
SQL: ".$query);
$data=mysql_fetch_array($result);













================================================
the 'name' and 'author' values print all the time with no problem. The
body values sometimes print, sometimes print part of the data, and
sometimes print nothing.

I did notice this, though:

if one record's body contained "this is some text" without the quotes,
it wouldn't show up in the text area. I had another record with a body like

this is some text



and it printed

this is some text

">

any rules or weirdness I'm not aware of when printing field contents to
textareas?

Re: need help w/ outputting to a textarea

am 02.05.2006 16:47:08 von nc

Jeff Brady wrote:
>
> My problem is with trying to print the data to a textarea
> (on a form, so the data can be edited)
....
>
....
>
> any rules or weirdness I'm not aware of when printing field
> contents to textareas?

Yes. The text inside textarea should be output between , not in the "value" attribute of the

Also note (although it is not related to the matter at hand) that
indexes of associative arrays should be quoted (e.g., $data['body'],
not $data[body]). The latter syntax works for now (when PHP encounters
$data[body], it automatically defines a constant whose name and value
are the same), but can become deprecated at any time without a warning.


Cheers,
NC

Re: need help w/ outputting to a textarea

am 02.05.2006 17:00:02 von Jeff Brady

NC wrote:
> Jeff Brady wrote:
>
>>My problem is with trying to print the data to a textarea
>>(on a form, so the data can be edited)
>
> ...
>
>>
>
> ...
>
>>any rules or weirdness I'm not aware of when printing field
>>contents to textareas?
>
>
> Yes. The text inside textarea should be output between , not in the "value" attribute of the
>
> Also note (although it is not related to the matter at hand) that
> indexes of associative arrays should be quoted (e.g., $data['body'],
> not $data[body]). The latter syntax works for now (when PHP encounters
> $data[body], it automatically defines a constant whose name and value
> are the same), but can become deprecated at any time without a warning.
>
>
> Cheers,
> NC

That was exactly it .. thanks! Apparently I forgot my basic HTML skills
somewhere along the way. =)

I also took your advice about the quotes. Thanks again!

Jeff