Reputation: 57
I've got several text boxes in a form that are the input to a SQL query. I need one of the boxes to auto populate with today's date but can't get it to work :
<td align="left"><INPUT TYPE="text" MAXLENGTH="10" SIZE="10" NAME="To_Date" id=To_Date value="'.date("m/d/y").'"/></td>
displays the following in the text box:
'.date(
Help is much appreciated!
Cheers,
Rene
Upvotes: 3
Views: 32626
Reputation: 9344
Not sure why everyone is using type="text"
type="date"
When using php date in the input date value, make sure the format is correct.
If not it will not work.
Use the format Y-m-d
(separted by hyphen but in reverse order)
<input type="date" value="<?php echo date("Y-m-d");?>">
d-m-Y
(using the hyphen, but placing date at the start)
d/m/Y
(using slash)
Y/m/d
(using slash in reverse order)
Upvotes: 1
Reputation: 1
Try this it worked for me.
<input type="text" name="Date" readonly = "readonly" value="<?php echo date('m/d/y');?>"/>
Upvotes: 0
Reputation: 36181
You're trying to use PHP in a HTML tag. You have to open the <?php
tag before writing any PHP code. So your code should be:
<td align="left">
<input type="text" maxlength="10" size="10" name="To_Date" id="To_Date" value="<?php echo date("m/d/y") ?>"/>
</td>
PS: Conventions want to use lowercase attributes in HTML, so I transform a little your input ;) (Yours was HTML5 valid, but it's just convention, deh.)
Upvotes: 0
Reputation: 28773
Try with either one like
PHP in HTML :
<input type="text" value="<?php echo date('m/d/y');?>"/>
HTML in PHP :
<?php echo "<input type='text' value='".date('m/d/y')."'";?>
Dont mesh both PHP
and HTML
and another is better to write HTML
in lower cases.
Upvotes: 8
Reputation: 1635
alternatively you can use.
echo '<input type="text" value="'.date('m/d/y').'"/></td>';
Upvotes: 0