jeff5656 Posted March 5, 2008 Share Posted March 5, 2008 In a form, I want the current date to be in the date field as a default (but the user can delete that and enter their own if they want). The following was tried but date is not display when I run the script <php $current_date = date (M j y); [.... snip some code here such as creting the form, etc.] <th scope="col"><div align="left">Date of consult: </div></th> <th scope="col"><div align="left"> <input type="text" name="$current_date" /> Now I tried that with and without the $ sign. Thank you. Will display more code if you need it, but the form itself comes aftrer the <html> and <form> but the ?> is at the very end of the whole thing... Quote Link to comment Share on other sites More sharing options...
jeff5656 Posted March 5, 2008 Author Share Posted March 5, 2008 I couldnt edit my post I meant this: $current_date = date ("M j y"); <input type="text" name="current_date" value="$current_date" /> but this also does not work: <input type="text" name="current_date" value="current_date" /> (they just dump that specific text into the field). Quote Link to comment Share on other sites More sharing options...
revraz Posted March 5, 2008 Share Posted March 5, 2008 Looks like you are trying to do this in HTML, try this instead <input type="text" name="<?php echo $current_date ?>" value="current_date" /> If this is PHP and not HTML, the post the code around it and not just a snippet. Quote Link to comment Share on other sites More sharing options...
craygo Posted March 5, 2008 Share Posted March 5, 2008 if you are putting the input outside of php tags then use this <input type=text name="current_date" value="<?php echo $current_date; ?>" /> if you are inside php tags then this <?php echo "<input type=text name=\"current_date\" value=\"".$current_date."\" /> ?> Ray Quote Link to comment Share on other sites More sharing options...
jeff5656 Posted March 5, 2008 Author Share Posted March 5, 2008 Thank you that worked! (I was inside html FYI). Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.