douqiao8370 2017-04-11 05:43
浏览 184
已采纳

我无法正确地将sql表中的文本回显到输入textarea框中

In my table there is a column Content with text:

<h2>LAGU</h2><p>Pada minggu ke kota.<br />Naik delman.</p><p>Pak kusir.</p>

This Content column collation is latin_swedish_ci and type is Text in the phpMyAdmin table structure.

In my PHP page, after the query - I give it a name $content

HTML:

<?php echo $content ?>

<form action="update.php" method="post" enctype="multipart/form-data">
    <div id="div_content">
    <label id="label_content">Content</label>
    <textarea id="content" name="content" value="<?php echo $content ?>"></textarea>
    </div>
</form>

The content did show correctly in the first echo. What is in header tag, shown as a header. What is in paragraph tag shown as a paragraph.

But the second echo (which is inside the textarea box), it doesn't show at all. I'm expecting that the textarea box will show exactly the same like the text from the php table, so in case there is a typo or something - the user can edit it directly inside the textarea box.

I've tried one apostrophe instead of double apostrophe

<textarea id="content" name="content" value='<?php echo $content; ?>'></textarea>

The textarea box still empty.

I've tried also this for the textarea

<textarea id="content" name="content" value='.<?php echo $content ?>.'></textarea>

and this

<textarea id="content" name="content" value="'.<?php echo $content ?>.'"></textarea>

Still empty.

But after I've tried this:

<textarea id="content" name="content" value=<?php echo $content ?>></textarea>

The text area box show like this:

LAGU</h2><p>Pada minggu ke kota.<br />Naik delman.</p><p>Pak kusir.</p>>

It lost the 'h2' tag in the beginning. And at the end it reads the closing '>' for the <textarea .....

But the weirdest thing is, if in the PhpMyAdmin I change the table content column by typing dar der dor (just plain text without any weird character), the textarea box is empty no matter what trick I did in the php page.

FYI, besides $content - I also have $title. In phpMyAdmin table, the title column text is MAMA. I put in the php page like this:

<input type="text" id="title" name="title" value="<?php echo $title ?>">

And the inputbox show MAMA.

  • 写回答

2条回答 默认 最新

  • dongsanhu4784 2017-04-11 05:51
    关注

    Change this line:

    <textarea id="content" name="content" value="<?php echo $content ?>"></textarea>
    

    to

    <textarea id="content" name="content"><?php echo $content; ?></textarea>
    

    and try again.

    Explanation: texarea don't have value attribute in it. The value you see is the innerHTML of textarea. So what ever you want to print is between <textarea><?php echo $content; ?></textarea>

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog