aashcool198 Posted June 9, 2009 Share Posted June 9, 2009 i want to input date using html form. the input will be stored in date format in database. what input field should i use so that user can fill date. Please someone tell me that code. Quote Link to comment https://forums.phpfreaks.com/topic/161508-solved-input-date/ Share on other sites More sharing options...
947740 Posted June 9, 2009 Share Posted June 9, 2009 As I see it, there are several options. I know of several javascript scripts that popup and let you choose the date. Or could just use a textfield and put the requested format next to it (like mm/dd/yy). When you process that with the php script, you will want to format the date accordingly. Using $date = strtotime($_POST['date']) and then take the date("n/j/Y",$date) will give you a good format. Then you just insert into the database. Quote Link to comment https://forums.phpfreaks.com/topic/161508-solved-input-date/#findComment-852300 Share on other sites More sharing options...
aashcool198 Posted June 10, 2009 Author Share Posted June 10, 2009 i input date as: Quote <input type="date" name="date"> and retrieve it using Quote $date = strtotime($_POST['date']); $deadline = date("n/j/Y",$date); and add in database: Quote $add_deadline = "INSERT INTO goals_deadline (goal_id, deadline) VALUES ('$goal_id','$deadline')"; $result = mysql_query ($add_deadline) or die(mysql_error()); But the date is not inserted in database. echo $deadline; is giving the correct value but it is not inserted in database while the $goal_id is being inserted every time. Please Help! Quote Link to comment https://forums.phpfreaks.com/topic/161508-solved-input-date/#findComment-852916 Share on other sites More sharing options...
thebadbad Posted June 10, 2009 Share Posted June 10, 2009 There's no date type for input fields, use text instead: <input type="text" name="date" /> And try inserting a date in the standard format instead (YYYY-MM-DD), your current format is not recognized by MySQL: $date = strtotime($_POST['date']); $deadline = date('Y-m-d', $date); Quote Link to comment https://forums.phpfreaks.com/topic/161508-solved-input-date/#findComment-852921 Share on other sites More sharing options...
aashcool198 Posted June 10, 2009 Author Share Posted June 10, 2009 Hey! thanks a lot to both of you! Quote Link to comment https://forums.phpfreaks.com/topic/161508-solved-input-date/#findComment-852976 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.