Skipjackrick Posted February 12, 2008 Share Posted February 12, 2008 I have only shown a portion of the form but anyways...... When a user submits a date on the form below, the user chooses the year ("yyyy") month ("mm") and day ("dd"). Each piece of the form populates my database table "date" which has 3 fields (yyyy, mm, dd). The db fields are set as TINYINT(4). But, I have noticed that there is an option to set the db field as "DATE" Is there a better way to submit dates that I am not aware of? Is it possible to submit dates into one field rather than 3?? I tried an internet search and it comes back with all sorts of junk. It may be too simple to find a tutorial on. <html> <head> </head> <body> <form action="" method="POST" enctype="multipart/form-data" name="form1" id="form1"> <td><span class="style1">Date of Catch</span></td> <td><select name="yyyy" id="yyyy"> <option value="2008" selected="selected">2008</option> <option value="2009">2009</option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> </select> <select name="mm" id="mm"> <option value="00">Select Month</option> <option value="01">January</option> <option value="02">February</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="dd" id="dd"> <option value="00">Select day</option> <option value="01">1</option> <option value="02">2</option> <option value="03">3</option> <option value="04">4</option> <option value="05">5</option> <option value="06">6</option> <option value="07">7</option> <option value="08">8</option> <option value="09">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></td> <td colspan="2"> <div align="center"> <input type="Submit" name="Submit" id="Submit" value="Submit" /> <input type="reset" name="clear" id="clear" value="Clear" /> </div></td> </tr> </table> </div></td> </tr> </form> </body> <html> Quote Link to comment https://forums.phpfreaks.com/topic/90776-submitting-date-to-mysql-db/ Share on other sites More sharing options...
revraz Posted February 12, 2008 Share Posted February 12, 2008 The DATE field is YYYY-MM-DD format. Quote Link to comment https://forums.phpfreaks.com/topic/90776-submitting-date-to-mysql-db/#findComment-465325 Share on other sites More sharing options...
Skipjackrick Posted February 12, 2008 Author Share Posted February 12, 2008 The DATE field is YYYY-MM-DD format. So in my form would I just have each <input> with the exact same id?? I am not sure how to code the form along with the php to where its all in one field. This is what my php looks like. With the form beneath it. <html> <head> </head> <?php if (isset($_POST['Submit'])) { $yyyy = $_POST['yyyy']; $mm = $_POST['mm']; $dd = $_POST['dd']; # THIS CODE TELLS MYSQL TO INSERT THE DATA FROM THE FORM INTO YOUR MYSQL TABLE $sql = "INSERT INTO $db_table(yyyy, mm, dd) values (''$yyyy', '$mm', '$dd', '$pic')"; if($result = mysql_query($sql ,$db)) { echo "Thank you, Your information has been entered into the database"; } else { echo "ERROR: ".mysql_error(); } } else { ?> <body> <form action="" method="POST" enctype="multipart/form-data" name="form1" id="form1"> <td><span class="style1">Date of Catch</span></td> <td><select name="yyyy" id="yyyy"> <option value="2008" selected="selected">2008</option> <option value="2009">2009</option> <option value="2010">2010</option> <option value="2011">2011</option> <option value="2012">2012</option> </select> <select name="mm" id="mm"> <option value="00">Select Month</option> <option value="01">January</option> <option value="02">February</option> <option value="03">March</option> <option value="04">April</option> <option value="05">May</option> <option value="06">June</option> <option value="07">July</option> <option value="08">August</option> <option value="09">September</option> <option value="10">October</option> <option value="11">November</option> <option value="12">December</option> </select> <select name="dd" id="dd"> <option value="00">Select day</option> <option value="01">1</option> <option value="02">2</option> <option value="03">3</option> <option value="04">4</option> <option value="05">5</option> <option value="06">6</option> <option value="07">7</option> <option value="08">8</option> <option value="09">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></td> <td colspan="2"> <div align="center"> <input type="Submit" name="Submit" id="Submit" value="Submit" /> <input type="reset" name="clear" id="clear" value="Clear" /> </div></td> </tr> </table> </div></td> </tr> </form> </body> <html> Quote Link to comment https://forums.phpfreaks.com/topic/90776-submitting-date-to-mysql-db/#findComment-465335 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.