|
Notices |
|
Thread Tools | Rate Thread | Display Modes |
05-27-2013, 12:45 AM | #1 |
Registered User
Join Date: Mar 2013
Posts: 246
|
Inserting dates into a database posted from html form.
Hi team!
I am feeding data into a database using a html form with date text input field. I don't want to enter the current date as what I am recording happened in the previous but I still need to calculate the number of days, months and years since the event occured. I have writen the following code to insert date into the database table: $event_date=mysql_real_escape_string($_POST['date']); $event_date=date('Y-m-d,strtotime($event_date)); $insert_date=maysql_query("insert into table_name(date_field)VALUES('$event_date')"; surpringly, the insert query is inserting 0000-00-00. The user is entering date in m-d-yyyy format. I have validated the user input date using the following code: $date_arr = explode('-', $event_date); if (checkdate($date_arr[0], $date_arr[1], $date_arr[2])==false) { // valid date ... $errors[]="What you entered is not a valid date format"; } the validation have worked fine. This is my question: What is going wrong in that the query is inserting 0000-00-00 instead of the date value? When echo the $event_date before inserting into the database is like is working fine. Any help please.thank you in advance.
__________________
To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. | To view links or images in signatures your post count must be 10 or greater. You currently have 0 posts. |
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
javascript and HTML for the form fields you will need to edit | omxwebtech | General Discussion | 1 | 09-10-2012 10:20 PM |
HTML 5 and HTML 4 | johnhedberg3 | HTML / DHTML | 3 | 06-16-2012 04:08 AM |
Plastic Surgeons Database of United States (Phone, Address, Zip) | immediate | Post your ad here | 0 | 05-09-2012 12:11 AM |
1.Basic distinguishing features of HTML 4 and HTML 5 | rooseveltjobs | HTML / DHTML | 0 | 04-12-2012 10:00 PM |
form to file script. php or html | mjvndhsb | PHP / mySQL | 0 | 10-07-2011 08:55 PM |