dtsnx44260 2014-04-03 21:15
浏览 34
已采纳

将数据显示到输入文本字段时出错

I'm having a problem trying to display the data into a input field, instead of display What is on the database it display ' $row[coursename] ', the one that is on the <td> works fine.

Any ideas of How to fix this, I'm really new with php

<?php
 require("coneccion.php");

if(empty($_SESSION['user']))
{
  header("Location: index.php");
  die("Redirecting to index.php");
}

$query = "SELECT courseid, coursename, id FROM courses where courseid = 179";

try
{
  $stmt = $db->prepare($query);
  $stmt->execute();
}
catch(PDOException $ex)
{
  die("Error");
}

$rows = $stmt->fetchAll(); 
?>
<table>
  <tr>
    <th>Name</th> 
  </tr> 
  <?php 
  foreach($rows as $row):   
    echo "<tr>";

      echo '<td><a href="#">' . htmlentities($row['coursename'], ENT_QUOTES, 'UTF-8') . '</a></td>';
      echo '<input type="text" name="coursename" value=" $row[coursename] " />';
      echo '</tr>';

    endforeach;
echo "</table>";
  • 写回答

2条回答 默认 最新

  • doujingqu3030 2014-04-03 21:18
    关注

    Move the variable outside of the string:

    echo '<input type="text" name="coursename" value="' .htmlentities($row['coursename']) . '" />';
    

    You can't add double quotes around it without also adding brackets (but that invovles a lot of error-prone escaping)

    echo "<input type=\"text\" name=\"coursename\" value=\"{htmlentities($row['coursename'])}\" />";
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探