I need to combine day, month and year in PHP in order to insert it to MySQL database. How I'll combine the day, the month and the y开发者_StackOverflow社区ear? I'm choosing the date from a drop down menu.
MySQL expects the date in this format: yyyy-mm-dd, so if you are using seprate drop downs for day, month and year you can cocatenate them like so:
$date = $_POST['year'] . '-' . $_POST['month'] . '-' . $_POST['day'];
If your form's method is 'get' instead of 'post', then substitute $_POST with $_GET in the code. Also make sure the value is set correctly for days 1 to 9 as 01 to 09 and you use a two digit value - the same for month. I.e.
<select name="month">
<option value="01">1</option>
...
</select>
If the drop-downs have numeric values, you can just use ordinary date adding functions.
精彩评论