将数据库中的结果导入textarea

Stu*_*Rik -1 html

我有一个编辑页面,用数据库中的原始内容填充内容,我使用内联php,它用标题填充字段,所有其他字段也可以.当我尝试使用相同的方法填充textarea时,它不起作用.除了作为文本的textarea之外,所有其他字段都是varchar.php是表单的值.

            require_once('includes/db.inc.php');
            $stmt = $mysqli->prepare("SELECT
                            postID,title,content,author,image 
                            FROM posts where postID = ?");
            $stmt->bind_param("i",$_GET['postID']);
            $stmt->execute();
            $stmt->bind_result($postID,$title,$content,$author,$image);
            $stmt->fetch();
            $stmt->close();


            ?>
            <section id="createPost">
                <form method="post" action="editPost.php">
                    <fieldset>
                        <legend>Edit Post: <?php echo $title ?></legend>
                        <input name="postID" type="hidden" value="<?php echo $postID; ?>">
                        <label for="titleOfPost">Title of Post:</label><br />
                        <input type="text" name="titleOfPost" size="82" placeholder="Enter title of post" required value="<?php echo $title ?>"><br />
                        <label for="bodyOfPost">Content of Post:</label><br />
                        <textarea cols="60" name="postContent" rows="10" placeholder="HTML tags allowed" value="<?php echo $content ?>"></textarea><br />
                        <label for="authorOfPost">Author:</label><br />
                        <input type="text" name="authorOfPost" size="82" placeholder="Author name" required value="<?php echo $author ?>"><br />
                        <label for="imageOfPost">Image:</label><br />
                        <input type="text" name="imageOfPost" size="82" placeholder="image" value="<?php echo $image ?>"><br />


                        <input type="submit" name="newPostBtn" value="EditPost" id="newPostBtn"/>
                    </fieldset>
                </form>
            </section><!--end createPost-->
Run Code Online (Sandbox Code Playgroud)

Vas*_*hev 6

Textarea元素没有属性.使用:

<textarea cols="60" name="postContent" rows="10" placeholder="HTML tags allowed"><?php echo $content ?></textarea>
Run Code Online (Sandbox Code Playgroud)


Cra*_*der 5

Textareas不像其他输入类型那样填充.内容位于不在开始标记内的标记(如锚标记)之间(如图像标记).

  • @StudentRik [阅读文档](http://www.w3.org/TR/html4/interact/forms.html#h-17.7).`textarea`没有'value`属性. (2认同)