Jump to content

Recommended Posts

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?

 

 

Link to comment
https://forums.phpfreaks.com/topic/166487-php-mysql-dateday/
Share on other sites

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).

Link to comment
https://forums.phpfreaks.com/topic/166487-php-mysql-dateday/#findComment-877944
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.