We have to insert the Date of Birth(which is a drop down box containing DD/MM/YYYY) in MySql by validating it. How can it be done?
Its a form validation for Date of Birth which is input by user from the options in dropdown menu.My question is how to insert that input DOB in MySql using PHP
Your question is a bit confusing. Inserting data ‘by validating it’ doesn’t make sense.
If you want to know how to insert data, well that’s a basic MySQL question which is probably best answered by consulting the online documentation.
If you want to know how to validate the data, you’re going to have to specify the kind of validation you want–as sanders has answered. It’s sort of like asking ‘how do I make a GUI?’ There are infinite ways you can do it. The question is too vague.
If you just want to check to see if the value submitted is a valid date, a quick and dirty (lazy) way of doing it is just to insert it into the table (assuming you have a column of the DATE/DATETIME type), then make a follow-up query to retrieve the value stored. If the stored value is that data type’s ‘zero’ value (i.e. ‘0000-00-00’ or ‘0000-00-00 00:00:00’), then the submitted value was not a valid date.
So your code would look something like:
Of course, there are many drawbacks to the above code. Ideally, you probably want to validate the data before you insert it, and if you are updating a record rather than inserting a new one, then you will need to fetch the original value before it is overwritten with an invalid one.
BTW: I think you meant to say ‘drop-down list’ or ‘select list.’ A drop-down menu is something else.