簡體   English   中英

PHP的形式回聲不起作用

[英]php form echo not working

我正在運行一條select語句來檢索數據庫值。 然后,我將檢索到的數據顯示/回顯到表單字段中。

“作者”數據正確顯示在“作者”字段中

正確顯示“關鍵字”數據

但是,來自“ content”變量的數據未以textarea形式顯示。 我知道語句中缺少值=,但這並沒有什么不同

我已經使用echo來確認$ content變量包含必需的數據

我是否缺少明顯的東西? 任何幫助,不勝感激:)

<?php

  if(isset($_GET['edit_post'])) { 
  $edit_id = $_GET['edit_post'];

  $select_post = "select * FROM posts WHERE post_id = '$edit_id'";  
  run_query = mysql_query($select_post);
  while($row_posts = mysql_fetch_array($run_query)) {

  $author = $row_posts['post_author'];
  $keywords = $row_posts['post_keywords'];     
  $content = $row_content['post_content'];
      }
  }
 ?>




      <tr> 
        <td align="right" bgcolor="#ccc"> Author:</td>
        <td><input type="text" name="post_author" value ="<?php echo $author;?>"/></td>
    </tr>   



     <tr> 
        <td align="right" bgcolor="#ccc"> Keywords:</td>
        <td><input type="text" name="post_keywords" size="100" value ="<?php echo     $keywords;?>"/></td>
    </tr>   



    <tr> 
        <td align="right" bgcolor="#ccc"> Content:</td>
        <td><textarea name="post_content" rows="10" cols="60"><?php echo $content;?>             </textarea></td>
    </tr>       

非常感謝,P

您錯誤地訪問了$content

$content = $row_content['post_content'];  

當您將查詢結果存儲在$row_posts ,它應該是

$content = $row_posts['post_content'];

嘗試這個

<?php

  if(isset($_GET['edit_post'])) { 
  $edit_id = $_GET['edit_post'];

  $select_post = "select * FROM posts WHERE post_id = '$edit_id'";  
  $run_query = mysql_query($select_post); 
  $author = "";
  $keywords = "";     
  $content = "";
  if(mysql_num_rows($run_query)>0) {
  $row_posts = mysql_fetch_array($run_query);
  $author = $row_posts['post_author'];
  $keywords = $row_posts['post_keywords'];     
  $content = $row_posts['post_content'];
      }
  }
 ?>

使用這個$content = $row_posts['post_content'];

而不是$content = $row_content['post_content'];

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM