Marcos01 Posted September 14, 2008 Share Posted September 14, 2008 Hi all, I would like to select a date and insert the date into the database. The date form has 3 dropdown boxes. Days, months and years. Can you help me with the code: This is what I have so far: The form: <form id="form1" name="form1" method="post" action=""> <label> Dag: <select name="day" id="day"> <option value="01">1</option> </select> Month: <select name="month" id=month"> <option> value="01"> id="1"</option> </select> Year: <select name="year" id=year"> <option> value="2008"> id="2008"</option> </select> PHP: <?php $date = $year $month $day ?> <?php $query ="INSERT INTO trainingsdata (date) values({$date})"; if (mysql_query($query, $connection)){ header("location: content.php"); exit; }else{ echo "data has not been added to database"; echo .mysql_error() .; } Quote Link to comment https://forums.phpfreaks.com/topic/124192-solved-form-date-insert-in-mysql-database/ Share on other sites More sharing options...
Mchl Posted September 14, 2008 Share Posted September 14, 2008 Start with this $date = "{$_POST['year']}-{$_POST['month']}-{$_POST['day']}"; Quote Link to comment https://forums.phpfreaks.com/topic/124192-solved-form-date-insert-in-mysql-database/#findComment-641301 Share on other sites More sharing options...
budimir Posted September 14, 2008 Share Posted September 14, 2008 You have a problem here: <select name="year" id=year"> <option> value="2008"> id="2008"</option> Do it like this: <select name="year" id=year"> <option value="" selected="selected"></option> <option value="2008" >2008</option> Apply the same to month and day. Was originaly working???? Quote Link to comment https://forums.phpfreaks.com/topic/124192-solved-form-date-insert-in-mysql-database/#findComment-641312 Share on other sites More sharing options...
Marcos01 Posted September 15, 2008 Author Share Posted September 15, 2008 Thanks Mchl and budimir. I corrected the typing error and added: $datum = $_POST['year']."-".$_POST['month']."-".$_POST['day']; With a little change from yours Mchl and it worked! <?php $datum = $_POST['year']."-".$_POST['month']."-".$_POST['day']; ?> <?php $query ="INSERT INTO trainingsdata (date) values({$date})"; if (mysql_query($query, $connection)){ header("location: content.php"); exit; }else{ echo "data has not been added to database"; echo .mysql_error() .; } Quote Link to comment https://forums.phpfreaks.com/topic/124192-solved-form-date-insert-in-mysql-database/#findComment-641995 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.