title: How to input Date and Time info from a PHP form into a MySQL table in datetime format
body: <p>I am a bit of a greenback here and looking for some help with some help with a formatting issue that I am having with one of my websites. </p>
  
  <p>I am trying to input Date and Time information inputted by a user into a MYSQL database in the datetime format. However when the user selects their date and time it will be done in the following format: 10:00 PM January 11, 2014</p>
  
  <p>Currently I am trying to input information from a set of drop down menus that are populated from my database into that same MYSQL database;</p>
  
  <pre><code>      &lt;tr&gt;
          &lt;td&gt;Time:&lt;/td&gt; 
          &lt;td&gt;
              &lt;select name="hour"&gt;
                  &lt;?php query_hour() ?&gt;
              &lt;/select&gt;                   
            :
              &lt;select name="minute"&gt;
                  &lt;?php query_minute() ?&gt;
              &lt;/select&gt;                   
              &lt;select name="ampm"&gt;
                  &lt;?php query_ampm() ?&gt;
              &lt;/select&gt;                   
          &lt;/td&gt;
        &lt;/tr&gt;
          &lt;tr&gt;
          &lt;td&gt;Date:&lt;/td&gt; 
          &lt;td&gt;
              &lt;select name="month"&gt;
                  &lt;?php query_month() ?&gt;
              &lt;/select&gt;
              &lt;select name="day"&gt;
                  &lt;?php query_day() ?&gt;
              &lt;/select&gt;
          ,
              &lt;select name="year"&gt;
                  &lt;?php query_year() ?&gt;
              &lt;/select&gt;
          &lt;/td&gt;
          &lt;/tr&gt;
  </code></pre>
  
  <p>The PHP that I use to input this information into the database is:</p>
  
  <pre><code>// scrub inputs
  $day = mysql_real_escape_string($_POST['day'], $conn);
  $month = mysql_real_escape_string($_POST['month'], $conn);
  $year = mysql_real_escape_string($_POST['year'], $conn);
  $minute = mysql_real_escape_string($_POST['minute'], $conn);
  $hour = mysql_real_escape_string($_POST['hour'], $conn);
  $ampm = mysql_real_escape_string($_POST['ampm'], $conn);
  
  // scrub date
  $date = date('Y-m-d G:i:s',strtotime($year.' '.$month.' '.$day.' '.$hour.' '.$minute.' '.$ampm));
  
  // prepare query
  $sql = "INSERT INTO my_db.events (eventtime)
   VALUES 
   ('$date')";
  
   // execute query
  mysql_query($sql);
  echo $sql;
  </code></pre>
  
  <p>When I submit the form it succeeds but submits generic time information instead of the user submitted information. Is there anyone that can provide a solution to this problem? I feel as though this is likely a duplicate question, but I have spent several hours perusing this forum as well as others with similar questions and have not found resolve.</p>
  
  <p>Thanks in advance, you have all been a huge help so far and I appreciate the support!</p>