Date input into MySql
Moderator: General Moderators
-
romanbills
- Forum Newbie
- Posts: 8
- Joined: Thu May 11, 2006 2:00 pm
Date input into MySql
For some reason MySQL doesn’t like me today. I'm convinced it’s moody. So here is what's going on:
I have a form that submits its information into my MySQL database. I’m looking to add the date to this submission to the database. Unfortunately everything I try doesn’t return errors it just doesn’t input the date into my database table...
Any help would be appreciated.
Thanks.
-Roman
I have a form that submits its information into my MySQL database. I’m looking to add the date to this submission to the database. Unfortunately everything I try doesn’t return errors it just doesn’t input the date into my database table...
Any help would be appreciated.
Thanks.
-Roman
-
romanbills
- Forum Newbie
- Posts: 8
- Joined: Thu May 11, 2006 2:00 pm
Type i just set to VarChar and im using
$time = date('D M j');
Iv tried all different ways to input it but for some reason it just wont do it. I'v used the time function in the form and then used POST that didnt work then i just used it in my "enter_it" script and attempted to use it as a var in that. Still didnt work. Im out of ideas.
$time = date('D M j');
Iv tried all different ways to input it but for some reason it just wont do it. I'v used the time function in the form and then used POST that didnt work then i just used it in my "enter_it" script and attempted to use it as a var in that. Still didnt work. Im out of ideas.
for starters, you should always use a date, datetime, or int (with unix timestamp) field for dates.
This is the only way that you'll be able to sort the date properly if you ever need to.
try something like this:
This is the only way that you'll be able to sort the date properly if you ever need to.
try something like this:
Code: Select all
$query = "INSERT INTO `myTable` (`date`) VALUES ('".date("Y-m-d"),strtotime($_POST['datefield']))."')";Mysql has more suited types for date and times.. Checkout the manual... (DATE seems most appropriate for you)romanbills wrote:Type i just set to VarChar and im using
Code: Select all
INSERT INTO column (datecolumn) VALUES (NOW())
-
romanbills
- Forum Newbie
- Posts: 8
- Joined: Thu May 11, 2006 2:00 pm
Thanks for the tip...
I just tried to use the previous suggestion and it now gives me an error
I get an un expected T_STRING error?
I just tried to use the previous suggestion and it now gives me an error
Code: Select all
$query="INSERT INTO registration(date,first_name,MI,last_name,title,day_phone,day_location,evening_phone,evening_location,mobile_phone,preffered_phone,fax,email) VALUES ('.date("Y-m-d"),strtotime($_POST['datefield'])).','$_POST[first_name]','$_POST[MI]','$_POST[last_name]','$_POST[title]','$_POST[day_phone]','$_POST[day_location]','$_POST[evening_phone]','$_POST[evening_location]','$_POST[mobile_phone]','$_POST[preffered_phone]','$_POST[fax]','$_POST[email]')";-
romanbills
- Forum Newbie
- Posts: 8
- Joined: Thu May 11, 2006 2:00 pm
So heres the new code that I just ran :
Its still returning the unknown T_STRING error. I cant identify anything wrong with it. This thing is haunting me.
Code: Select all
$query="INSERT INTO registration(date,first_name,MI,last_name,title,day_phone,day_location,evening_phone,evening_location,mobile_phone,preffered_phone,fax,email) VALUES ('date("Y-m-d"),strtotime($_POST['datefield'])','$_POST[first_name]','$_POST[MI]','$_POST[last_name]','$_POST[title]','$_POST[day_phone]','$_POST[day_location]','$_POST[evening_phone]','$_POST[evening_location]','$_POST[mobile_phone]','$_POST[preffered_phone]','$_POST[fax]','$_POST[email]')";try this:
Code: Select all
$query="INSERT INTO registration(date,first_name,MI,last_name,title,day_phone,day_location,evening_phone,evening_location,mobile_phone,preffered_phone,fax,email) VALUES ('".date("Y-m-d"),strtotime($_POST['datefield'])."','{$_POST[first_name]}','{$_POST[MI]}','{$_POST[last_name]}','{$_POST[title]}','{$_POST[day_phone]}','{$_POST[day_location]}','{$_POST[evening_phone]}','{$_POST[evening_location]}','{$_POST[mobile_phone]}','{$_POST[preffered_phone]}','{$_POST[fax]}','{$_POST[email]}')";-
romanbills
- Forum Newbie
- Posts: 8
- Joined: Thu May 11, 2006 2:00 pm
- xpgeek
- Forum Contributor
- Posts: 146
- Joined: Mon May 22, 2006 1:45 am
- Location: Kyiv, Ukraine
- Contact:
It worked!
Code: Select all
$query="INSERT INTO registration(date,first_name,MI,last_name,title,day_phone,day_location,evening_phone,
evening_location,mobile_phone,preffered_phone,fax,email)
VALUES ('".date("Y-m-d")."','{$_POST[first_name]}','{$_POST[MI]}','{$_POST[last_name]}',
'{$_POST[title]}','{$_POST[day_phone]}','{$_POST[day_location]}','{$_POST[evening_phone]}',
'{$_POST[evening_location]}','{$_POST[mobile_phone]}','{$_POST[preffered_phone]}',
'{$_POST[fax]}','{$_POST[email]}')";-
romanbills
- Forum Newbie
- Posts: 8
- Joined: Thu May 11, 2006 2:00 pm