简体   繁体   English

PHP的形式回声不起作用

[英]php form echo not working

I'm running a select statement to retrieve db values. 我正在运行一条select语句来检索数据库值。 I then and display / echo the retrieved data into the form fields. 然后,我将检索到的数据显示/回显到表单字段中。

The 'author' data displays correctly in the author field “作者”数据正确显示在“作者”字段中

The 'keywords' data displays correctly 正确显示“关键字”数据

However the data from the 'content' variable isn't displaying the in the form textarea. 但是,来自“ content”变量的数据未以textarea形式显示。 I'm aware the value = is missing from the statement, but this does not make a difference 我知道语句中缺少值=,但这并没有什么不同

I have used echo to confirm that the $content variable contains the required data 我已经使用echo来确认$ content变量包含必需的数据

Am I missing something obvious? 我是否缺少明显的东西? Any help greatly appreciated :) 任何帮助,不胜感激:)

<?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>       

many thanks, P 非常感谢,P

You are accessing $content wrongly 您错误地访问了$content

$content = $row_content['post_content'];  

As you are storing the query result in $row_posts , it should be 当您将查询结果存储在$row_posts ,它应该是

$content = $row_posts['post_content'];

try this 尝试这个

<?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'];
      }
  }
 ?>

use this one $content = $row_posts['post_content']; 使用这个$content = $row_posts['post_content'];

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM