我有一个HTML表单,它将两个字段写入MySql数据库。那部分工作正常。现在,我正在尝试使用该数据库中的值预填充表单上的两个字段。这样,在保存数据后刷新屏幕,或者用户在后续访问时显示页面时,将使用数据库中的值预先填充该字段。其中一个变量字段是$ home_text。我暂时在页面上回显了$ home_text的值,它显示了字段中的所有单词。但是,当我尝试在Input的Value子句中使用$ home_text时,它会在第一个空格后截断字段值。如何让HTML表单显示$ home_text的整个值而不截断第一个空格?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
</head>
<body>
<form name="Form1" id="Form1" action="post_mess_age.php" method="post">
<?php
$servername = "localhost";
$username = "myUser";
$password = "myPassword";
$dbname = "myDBName";
// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);
// Check connection
if (!$conn) {
die("Connection failed: " . mysqli_connect_error());
}
$sql = "SELECT notice from notification where page = 'home' limit 1";
$result = mysqli_query($conn, $sql);
if (!$result)
{
echo 'Could not run query: ' . mysql_error();
exit;
}
$row = mysqli_fetch_row($result);
echo $row[0] . "<br>";
$home_text = $row[0];
echo 'Home_text is :' . $home_text . "<br>";
mysqli_close($conn);
?>
<table class="table_800">
<tr>
<td width="480" align="left">
<input type="text" size="80" maxlength="400"
name="home_page_text" id="home_page_text"
value=<?php echo $home_text?>"
style="background-color:#FFC" />
</td>
</tr>
</table>
</form>
</body>
答案 0 :(得分:0)
看起来值属性在输入中缺少双引号,这可能是问题吗?
value=<?php echo $home_text?>"
value="<?php echo $home_text?>"