4

在我的表单中,我有以下基于标准 PHP/MySql 查询的值。

echo "<tr>\n
        <td align='right'><b>Location</b></td>
        <td><input name='student_location' type='text' size='25' style='font-weight: 700' value=$location></td>
    </tr>";

当 的值为$location一个单词时,它会正确显示,当它是多个单词时,说“North Campus”,仅显示“North”。

我已经检查了两倍和三次,并且正确的值在数据库中,当我对 $location 的值进行回显时,它回显了正确的值,但是当它显示在上面的字段中时,它会砍掉最后一个单词。它对我所有不止一个词的变量都这样做,所以我错过了一些明显的东西。

4

3 回答 3

8

你忘了引号:

echo "<tr>\n
    <td align='right'><b>Location</b></td>
    <td><input name='student_location' type='text' size='25' style='font-weight: 700' value=\"$location\"></td>
</tr>";

如果没有引号,第一个单词会被注明,其他单词将被解释为错误的属性。

于 2012-05-29T19:37:59.227 回答
5

You need to put your single quotes around it to make it a valid attribute. The HTML is being created as value=North Campus which gets interpreted as value="North" and some Campus attribute that has no value. Use value='$location'.

于 2012-05-29T19:38:15.760 回答
4

你需要通过转义 "

echo "<tr>\n
        <td align='right'><b>Location</b></td>
        <td><input name='student_location' type='text' size='25' style='font-weight: 700' value=\"$location\"></td>
    </tr>";
于 2012-05-29T19:37:57.697 回答