I have an html form from which I am trying to insert the data into a MySQL db. I have heard that the date needs to be in a specific format for inserting into the table, I believe it was YearDayMonth (20070612) Is this true? Because of that, I broke the date into 3 fields with drop down menus to make sure that I got the information in the correct format. Maybe there was an easier way to script this, but this is what I came up with:

<p>Date: <select name="date_month">
	<option value="jan">January</option>
	<option value="feb">Febuary</option>
	<option value="mar">March</option>
	<option value="apr">April</option>
	<option value="may">May</option>
	<option value="jun">June</option>
	<option value="jul">July</option>
	<option value="aug">August</option>
	<option value="sep">September</option>
	<option value="oct">October</option>
	<option value="nov">November</option>
	<option value="dec">December</option>
	</select>
	<select name="date_day">
		<option value="1">1</option>
		<option value="2">2</option>
		<option value="3">3</option>
		<option value="4">4</option>
		<option value="5">5</option>
		<option value="6">6</option>
		<option value="7">7</option>
		<option value="8">8</option>
		<option value="9">9</option>
		<option value="10">10</option>
		<option value="11">11</option>
		<option value="12">12</option>
		<option value="13">13</option>
		<option value="14">14</option>
		<option value="15">15</option>
		<option value="16">16</option>
		<option value="17">17</option>
		<option value="18">18</option>
		<option value="19">19</option>
		<option value="20">20</option>
		<option value="21">21</option>
		<option value="22">22</option>
		<option value="23">23</option>
		<option value="24">24</option>
		<option value="25">25</option>
		<option value="26">26</option>
		<option value="27">27</option>
		<option value="28">28</option>
		<option value="29">29</option>
		<option value="30">30</option>
		<option value="31">31</option>
		
	</select>
	<select name="date_year">
		<option value="07">2007</option>
		<option value="08">2008</option>
		<option value="09">2009</option>
	</select>

My question is, what is the script to change the three fields into one variable to be added to the table? Do I just do something like $TIMESTAMP=(date_year + date_day + date_month) Another question that I had, does timstamp automatically make it the current date for when it is being inserted, or can I have it be user set like above?

Recommended Answers

All 4 Replies

Try using different values for your select options. It makes it much easier to assemble a date in the proper format, which is yyyy-mm-dd.

<select name="date_year">
<option value="2007">2007</option>

<select name="date_month">
<option value="01">January</option>

<select name="date_day">
<option value="01">1</option>

You can then assemble the date string in the proper format on the receiving end.

$theDate = $_POST."-".$_POST."-".$_POST;

Thanks TopDogger. I'll try and make those changes that you suggested.

I know I marked this as solved already, but I just noticed something. TopDogger recommended to use: $theDate = $_POST['date_year']."-".$_POST['date_month']."-".$_POST['date_day']; I just noticed that there are some '.' (dot) in the line. What is the reason for putting the dot there?

You use dots to concatinate string values in PHP. The dots do not appear in the final value.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.