BadGoat Posted August 16, 2006 Share Posted August 16, 2006 Hello!I wrote a little script which uses the MySQL date datatype which does not seem to be working at the moment. It worked just fine when I wrote it on my local machine, but it is no longer working now that it's up on the host. Can someone take a look and see if I did something wrong, or if it can be optimized to work in most situations?$sip=$_POST['sip'];$eip=$_POST['eip'];$nic=$_POST['nic'];$city_id=$_POST['city_id'];$country_id=$_POST['country_id'];$company_id=$_POST['company_id'];$contact=$_POST['contact'];$phone=$_POST['phone'];$e1=$_POST['e1'];$e2=$_POST['e2'];$e_ver=$_POST['e_ver'];$updated= date('M j Y');$sqlquery = "INSERT INTO ip_block VALUES('','$sip','$eip','$nic','$city_id','$country_id','$company_id','$contact','$phone','$e1','$e2','$e_ver','$updated')";$queryresult = mysql_query($sqlquery) or die(" Could not execute mysql query !");$sqlquery = "SELECT * from ip";and then where the date is echoed:<tr> <td class="selcol1">Date Updated</td> <td class="selcol2">' .$updated. '</td></tr> Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted August 16, 2006 Share Posted August 16, 2006 it is showing date well in my localhost:2112 too.. can you show me the out put in your server as well as in localhost? Quote Link to comment Share on other sites More sharing options...
BadGoat Posted August 16, 2006 Author Share Posted August 16, 2006 Well, on the page which echoes the date updated it does show the correct date, but when I check in PHPMYADMIN it shows 0000-00-00. Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted August 16, 2006 Share Posted August 16, 2006 Ok, change the field's type to "TEXT", which is going to save $updated.. i think it is in "DATE" or datetime format... just Alter that field to TEXT... coz date('M j Y'); will return "Aug 16 2006" which is having some alphabetic chars... so change that field's type to TEXT. Quote Link to comment Share on other sites More sharing options...
otuatail Posted August 16, 2006 Share Posted August 16, 2006 If you want to store a date in the database it has to be 'YYYY-MM-DD' you can display it in any format using strtotime() This is mine.$datetime = date('D d-M-Y', strtotime($row['Date'])); Quote Link to comment Share on other sites More sharing options...
BadGoat Posted August 16, 2006 Author Share Posted August 16, 2006 Yep, changing the data type from date to text fixed it. :) Many thanks! Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted August 16, 2006 Share Posted August 16, 2006 ok fine :)http://TopLancers.com Quote Link to comment Share on other sites More sharing options...
Barand Posted August 16, 2006 Share Posted August 16, 2006 [quote author=BadGoat link=topic=104530.msg416989#msg416989 date=1155757051]Yep, changing the data type from date to text fixed it. :) Many thanks![/quote]Bad choice. You should've gone with otuatail's solution. Quote Link to comment Share on other sites More sharing options...
GingerRobot Posted August 16, 2006 Share Posted August 16, 2006 [quote author=Barand link=topic=104530.msg417065#msg417065 date=1155765040][quote author=BadGoat link=topic=104530.msg416989#msg416989 date=1155757051]Yep, changing the data type from date to text fixed it. :) Many thanks![/quote]Bad choice. You should've gone with otuatail's solution.[/quote]Yes, this is because you will run into troubles if/when you need to perform things such as sorting on the date. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 16, 2006 Share Posted August 16, 2006 And the implication of that is you can't select records "..WHERE date > '$somevalue'", or '<'. You also deny yourself the ability to use the dozens of MySql date/time functions. Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted August 16, 2006 Share Posted August 16, 2006 [quote author=Barand link=topic=104530.msg417065#msg417065 date=1155765040][quote author=BadGoat link=topic=104530.msg416989#msg416989 date=1155757051]Yep, changing the data type from date to text fixed it. :) Many thanks![/quote]Bad choice. You should've gone with otuatail's solution.[/quote]I said a solution just for inserting date... and he likes to handle date('M j Y'); will return "Aug 16 2006"... for inserting these kind of date format "TEXT" field is easy. Quote Link to comment Share on other sites More sharing options...
Barand Posted August 16, 2006 Share Posted August 16, 2006 But what's the point of storing a date whose sole purpose is to look pretty. Dates should be stored for functionality. The format can be chosen as you please when you query the table or output it. Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted August 16, 2006 Share Posted August 16, 2006 [quote author=Barand link=topic=104530.msg417082#msg417082 date=1155766224]But what's the point of storing a date whose sole purpose is to look pretty. Dates should be stored for functionality. The format can be chosen as you please when you query the table or output it.[/quote] yes, agreed. but my answer will be easy for beginners. it is just inserting and showing a date. ;) Quote Link to comment Share on other sites More sharing options...
Barand Posted August 16, 2006 Share Posted August 16, 2006 It's just as easy to insert a date in 'Y-m-d' format as it is to use 'M j Y'.Why should they be given poor advice just because they are beginners? Quote Link to comment Share on other sites More sharing options...
karthikeyan_coder Posted August 16, 2006 Share Posted August 16, 2006 he didnt mentioned any qurries like WHERE `date` > ... like that... he just asked to insert. thats it. i said just for a quick solution not a geeky solution. lol ;) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.