我有一個編輯頁面,用數據庫中的原始內容填充內容,我使用內聯php填充字段和所有其他字段。當我嘗試使用相同的方法填充textarea時,它不起作用。 所有其他字段都是varchar,除了textarea是文本。 php是在窗體的值。從數據庫中獲取結果到textarea
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-->
每當某些事情不能正常工作時,始終總是始終總是始終查看生成的HTML源代碼。如果你這樣做了,你會發現數據實際上被髮送到瀏覽器,並且知道這不是一個PHP/MySQLi問題,而是一個由於對textarea標籤誤解而造成的簡單HTML問題。 – kba