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 请完成下列相关问题!
  • ¥15 drone 推送镜像时候 purge: true 推送完毕后没有删除对应的镜像,手动拷贝到服务器执行结果正确在样才能让指令自动执行成功删除对应镜像,如何解决?
  • ¥15 求daily translation(DT)偏差订正方法的代码
  • ¥15 js调用html页面需要隐藏某个按钮
  • ¥15 ads仿真结果在圆图上是怎么读数的
  • ¥20 Cotex M3的调试和程序执行方式是什么样的?
  • ¥20 java项目连接sqlserver时报ssl相关错误
  • ¥15 一道python难题3
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机