Hi everyone,
My HTML5 page contains a form with input type “date”. I try to add a row using the code annexed but I fail to have an additional row in my table. Can anyone suggest where have I gone wrong?
Thanks !
Sorry, I didn’t notice that comment in your original post. Clearly, as you’ve defined the column in the database a a “date”, you know that it needs to be in yyyy-mm-dd format, so if your users type it in “backwards” as dd-mm-yyyy, you’ll either have to make them not do that, or change your code so that it reverses it.
When you try to store something in a date column, MySQL will only store the data if it is a valid date. When the user types it in backwards (compared to how MySQL stores a date) it comes back as invalid and a blank date is stored. In your PHP code, you need to validate that they’ve entered a proper date, then once you’re satisfied that they have, convert it into the format that MySQL needs, then store it.
mySQL expects dates being saved to be initially in YYYY-MM-DD format which it then converts to its own internal format. When reading it back you can tell mySQL to use whatever format you like. The YYYY-MM-DD only applies to dates that are to be converted to the internal storage format.