将 PHP 变量作为文本框值 [英] Putting a PHP variable as a text box value
问题描述
我正在尝试编写将 php 变量作为文本框值传递的代码.这是我尝试的以下代码:
I am trying to write code that passes a php variable as a textboxes value. Here is the following code I tried:
echo "<td>"."<input type='text' value='<?php echo $start_date; ?>'/>"."</td>"
这带来了一个错误:解析错误:语法错误,意外的 T_ECHO,期待 ',' 或 ';'
This brings up an error : Parse error: syntax error, unexpected T_ECHO, expecting ',' or ';'
我尝试了各种重新措辞的方法:
I have tried various methods of re-wording:
echo "<input type='text' value='<?php echo $start_date?>'/>";
(这纯粹是为了测试,因为我希望结果在表格行中)
(this was purely to test as I would like the result in a table row)
但这表明:
<?php echo ?>
在文本框中,我也收到此错误:注意:未定义变量:start_date...
in the textbox and I also get this error: Notice: Undefined variable: start_date...
在此先感谢您的帮助.
推荐答案
您不需要在另一个echo
中启动一个echo
.变量 $start_date
可以在双引号内,因此可以进行插值.
You don't need to start one echo
within another. The variable $start_date
can be within double quotes and hence interpolated.
echo "<td><input type='text' value='$start_date'/></td>"; //no unnecessary concatentation
在关联数组的情况下,例如,回显$row['start_date']
In case of an associative array, for example, to echo $row['start_date']
echo "<td><input type='text' value='".$row['start_date']."/></td>";
这篇关于将 PHP 变量作为文本框值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!