在 textarea 中显示 PHP 查询结果

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17668213/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 16:14:00  来源:igfitidea点击:

Display PHP query result in textarea

phptextarea

提问by Héctor Rivera

I'm having a little problem over here, I'm trying to make a news system with an edit button, it's all going great but I'm having problems with the "textarea", I can display the results on inputs but when I try to display them in a textarea it wont, look:

我在这里遇到了一个小问题,我正在尝试制作一个带有编辑按钮的新闻系统,一切都很好,但是我遇到了“textarea”的问题,我可以在输入上显示结果但是当我尝试将它们显示在它不会的文本区域中,看看:

This code works perfectly:

此代码完美运行:

<input name="txt_02" size="87" maxlength="100" id="txt_Resumen" maxlength="140"  value="<?php echo $not_Resumen?>"/>

This wont:

这不会:

<textarea name="txt_descripcion" cols="66" rows="10" id="txt_descripcion"  value="<?php echo $not_Contenido ?>">
</textarea>

I tried with $not_Resumen and other ones in the textarea and it doesn't work, the textarea would show up empty without the text, it should be a little mistake I'm making but I can't find it. Thanks.

我尝试在文本区域中使用 $not_Resumen 和其他的,但它不起作用,文本区域会在没有文本的情况下显示为空,这应该是我犯的一个小错误,但我找不到它。谢谢。

回答by Dave Chen

Just put it within ><, there's no value attribute:

把它放在里面><没有 value 属性

<textarea name="txt_descripcion" cols="66" rows="10" id="txt_descripcion"><?php echo htmlspecialchars($not_Contenido);?></textarea>

You should also use htmlspecialcharsso that the textarea will not break if $not_Contenidocontains </textarea>.

您还应该使用,htmlspecialchars以便 textarea 在$not_Contenidocontains时不会中断</textarea>

This is sometimes overlooked, but if $not_Contenidocontained something like:

这有时会被忽视,但如果$not_Contenido包含以下内容:

</textarea><script src="http://remotedomain.com/evilscript.js"></script>

An attacker can run anything they want, and all your clients will download and run the script on your website. A common attack would be sending cookies to their domain.

攻击者可以运行他们想要的任何东西,并且您的所有客户端都将下载并在您的网站上运行该脚本。一种常见的攻击是将 cookie 发送到他们的域。

回答by Gautam3164

Try like

试试像

<textarea name="txt_descripcion" cols="66" rows="10" id="txt_descripcion">
     <?php echo $not_Contenido; ?>
</textarea>

We con't give value to the textbox.

我们不会赋予textbox.

回答by Praveen kalal

Value is not attribute of textarea so simply place between the tag <textarea>?</textarea>

值不是 textarea 的属性,所以只需放在标签之间 <textarea>?</textarea>

<textarea name="txt_descripcion" cols="66" rows="10" id="txt_descripcion" ><?php echo $not_Contenido ?>
</textarea>

回答by San

Place your value between opening and closing tags of textarea as like other HTML tags and textarea has no attribute "value"

将您的值放在 textarea 的开始和结束标记之间,就像其他 HTML 标记一样,并且 textarea 没有属性“值”

<textarea name="txt_descripcion" cols="66" rows="10" id="txt_descripcion"><?php echo htmlspecialchars($not_Contenido);?></textarea>