Putting a PHP variable as a text box value
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>"
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)
but this shows:
<?php echo ?>
in the textbox and I also get this error: Notice: Undefined variable: start_date...
Thanks in advance for any help.
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
EDIT:
In case of an associative array, for example, to echo $row['start_date']
echo "<td><input type='text' value='".$row['start_date']."/></td>";
你可以试试这个 -
echo "<td>"."<input type='text' value='$start_date;'/>"."</td>";
你必须回声一次,例如:
echo "<td>"."<input type='text' value='$start_date'/>"."</td>";
链接地址: http://www.djcxy.com/p/69868.html
下一篇: 把一个PHP变量作为文本框的值