2012-01-26 30 views
-1

我有一個編輯頁面,用數據庫中的原始內容填充內容,我使用內聯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--> 
+0

每當某些事情不能正常工作時,始終總是始終總是始終查看生成的HTML源代碼。如果你這樣做了,你會發現數據實際上被髮送到瀏覽器,並且知道這不是一個PHP/MySQLi問題,而是一個由於對textarea標籤誤解而造成的簡單HTML問題。 – kba

回答

5

Textarea元素不具有屬性。使用:

<textarea cols="60" name="postContent" rows="10" placeholder="HTML tags allowed"><?php echo $content ?></textarea> 
+0

Crashspeeder先來:) –

5

Textareas不像其他輸入類型那樣填充。內容在標籤之間(如錨標籤)不在開始標籤內(如圖像標籤)。

+0

我還需要php中textarea的值嗎?還是沒關係 – StudentRik

+0

textarea沒有value屬性,所以沒有。您只需使用'' – Crashspeeder

+2

@StudentRik [閱讀文檔](http://www.w3.org/TR/html4/interact/forms.html#h-17.7)。 'textarea'沒有'value'屬性。 – kba