gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-04 13:38:40 25 4
gpt4 key购买 nike

我在尝试将数据显示到输入字段中时遇到问题,而不是显示它显示的数据库中的内容 ' $row[coursename] ',<td> 上的那个工作正常。

关于如何解决这个问题的任何想法,我真的是 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>";

最佳答案

将变量移到字符串之外:

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

您不能在不添加括号的情况下在其周围添加双引号(但这会涉及很多容易出错的转义)

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

关于php - 将数据显示到输入文本字段中时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22849163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com