How do I include a php variable within the value element of an html input tag?

html, php

Solution

It's a good idea to always use full PHP tags, because that will keep your app from breaking if you move to a different server or your config is changed not to allow short tags.

?>
<input type="text" size="10" value="<?php
echo(date("Y-m-d", strtotime($rowupd['upcoming_event_featured_date'])));
?>"name="upcoming_event_featured_date" id="keys"/><?php

Also, note that you are missing the `;` from the end of your PHP code.

You may find it better to keep the whole thing in PHP too, and just `echo()` out the HTML, as that will keep you from having to switch back and forth from PHP to HTML parsing.

Problem

I am trying to include a value from a database table within the value element of an input field. This is what I have, but it is not working: ``` ?><input type="text" size="10" value="<?= date("Y-m-d", strtotime($rowupd['upcoming_event_featured_date'])) ?>" name="upcoming_event_featured_date" id="keys"/><?php ``` I have done this before, but I usually print it out like this: ``` print '<input type="text" size="10" value="'.date("Y-m-d", strtotime($rowupd['upcoming_event_featured_date'])).'" name="upcoming_event_featured_date" id="keys"/>'; ``` What is the appropriate way of doing this without using `print ''`?

Original source