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. 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. 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: <input type="date" name="date"> and retrieve it using $date = strtotime($_POST['date']); $deadline = date("n/j/Y",$date); and add in database: $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! 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); 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! Link to comment https://forums.phpfreaks.com/topic/161508-solved-input-date/#findComment-852976 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.