将文本区域数据保存在 php

Keeping textarea data in php

我想在 php 中保留一个文本区域数据,所以当我刷新页面时文本仍然存在。所以我尝试了这个,但每次我刷新页面时,文本都会消失。如果有人能帮助我,我将不胜感激。

PHP代码:

<?php 
$comments = "";
$comments= $_POST['comments'];
?> 

HTML代码:

<textarea name="comments" value="<?php echo $comments ?>" cols="30" rows="3" class="w3-input w3-round-large" placeholder="add some infos about yourself !!"></textarea><br>

textarea 没有 value 属性,所以如果你想在那里放一个值,你需要在标签中间进行:

<textarea name="comments" cols="30" rows="3" class="w3-input w3-round-large" placeholder="add some infos about yourself !!"><?php echo $comments ?></textarea>