Hello to everyone, im having trouble in inserting a date like "2012-12-06" into a database mysql, Im using phpmyadmin+wamp and adobe dreamweaver!I want to use 3 textfields, one for the year, other for the month and a last one for the day, but I always get an error by using this


I created 4 variables 3 of them ($field2_date,$field3_date,$field4_date) to get the year,month and day and one ($field_final_date1) to join the other 3 to form this "2012-12-06". I can i do this? I made this code here:

$query = sprintf("insert into despesas_casa values (NULL,'%s','%s','%s','%s','%s','%s','%s','%s')",$_POST['field1'],$_POST[$field_final_date1],$_POST['field5'],$_POST['field6'],$_POST['field7'],$_POST['field8'],$_POST['field9'],$_POST['field10']);

Recommended Answers

All 4 Replies

Member Avatar for diafol

You don't need to store your data like this. Just store the full date. You can use keywords like MONTH and YEAR to extract those values from a full date in mysql. A 'datepicker' may be a better option for retrieving a date than separate fields. However, if you envisage dates from years and years ago, a datepicker can be somewhat clumsy.

Hello thankyou for replying, i will search for info about using a datepicker! Thanks

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.