How to insert norman date in mysql using php? -


I'm completely new to php and mysql; Need some help with this, I want to put a date in mysql table, formatted as DD / MM / yay.

I have 4 columns in my table: id, name, age & amp; Birthday.

My HTML code

  & lt; Form action = "php_creat_cliente.php" method = "post" & gt; Name: & lt; Input name = "context" type = "article" /> gt; & Lt; Br / & gt; Age: & lt; Input name = "focus" type = "text" / & gt; & Lt; Br / & gt; Birthday: & lt; Input name = "date" type = "text" /> gt; & Lt; Br / & gt; & Lt; / Form & gt;   

My PHP-code

  & lt? Include php ('config.php'); $ Name = $ _ post ['name']; $ Age = $ _ post ['age']; $ Birthday = $ _ post ['birthday']; Include $ save = mysql_query values ​​("Debt (name, age, birthday) '(' $ name ',' $ age ',' $ birthday ')); Header (" location: index.html "); Exit );? & Gt;   

Currently, the date is entered in mm / dd / yyyy format, but I need it in DD / MM / yyyy format. < / div>

MySQL accepts a string in the format of 'yyyy-mm-dd' or 'yyyymmdd' for the date, Enter whatever format you want in the text field As long as you make sure that you have reproduced a valid format (as I mentioned) before sending it to the database (in your code).

Or you You can specify yourself as a format:

  $ save = mysql_query ("Include the loan (name, age, birthday) values ​​('$ name', '$ age', STR_TO_DATE   

This form is popular for dates. In the present way (The method shown here at least), and everything in between if you want to be a web developer, I recommend you to know about these attacks.

Edit:

Does a jQuery UI Datepicker help in choosing a date text field in a valid date format? You can specify the format in which you want the widget to show your date like this:

  $ ("#datepicker") .datepicker ("option", "dateFormat", " Dd-mm -Y y ");   

And then you can make sure that the MySQL submitting the date format in your order of your entry as I have shown above:

  STR_TO_DATE ('$ birthday', '% d-% m-% Y')    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -