Carl Posted July 19, 2009 Share Posted July 19, 2009 Hello, I am having a little trouble getting the date/day to stick to a php form so when access'd the date and day of that form will show. I have created a php form for storing pickup and drop off bookings for a transport company, for each day a new blank form and table is created, but I need to be able to enter the date on the current days form, and store it to that days mysql table, so the date and day is displayed on my php form. can anyone assist with this dilema? Quote Link to comment https://forums.phpfreaks.com/topic/166487-php-mysql-dateday/ Share on other sites More sharing options...
Daniel0 Posted July 19, 2009 Share Posted July 19, 2009 Well, say you have something like this in a form: <label for="pickupMonth">Month:</label> <select name="pickup[month]" id="pickupMonth"> <option value="1">January</option> <option value="2">February</option> <!-- etc. --> <option value="12">December</option> </select> <label for="pickupDay">Day:</label> <select name="pickup[day]" id="pickupDay"> <option value="1">1</option> <option value="2">2</option> <!-- etc. --> <option value="31">31</option> </select> <label for="pickupYear">Year:</label> <input type="text" name="pickup[year]" id="pickupYear"> Then you can do like this: if (!isset($_POST['pickup']['month']) || !isset($_POST['pickup']['day']) || !isset($_POST['pickup']['year'])) { echo 'please complete all fields'; } else if (!checkdate((int) $_POST['pickup']['month'], (int) $_POST['pickup']['day'], (int) $_POST['pickup']['year'])) { echo 'please enter a valid date'; } else { $mysqlDate = sprintf('%04d-%02d-%02d', $_POST['pickup']['year'], $_POST['pickup']['month'], $_POST['pickup']['day']); } To validate the date and make it fit a MySQL DATE field, which is stored in ISO 8901 format (that is YYYY-MM-DD). Quote Link to comment https://forums.phpfreaks.com/topic/166487-php-mysql-dateday/#findComment-877944 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.