Jump to content

Date() stopped working


BadGoat

Recommended Posts

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>
Link to comment
https://forums.phpfreaks.com/topic/17765-date-stopped-working/
Share on other sites

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.
Link to comment
https://forums.phpfreaks.com/topic/17765-date-stopped-working/#findComment-75828
Share on other sites

[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.
Link to comment
https://forums.phpfreaks.com/topic/17765-date-stopped-working/#findComment-75909
Share on other sites

[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.
Link to comment
https://forums.phpfreaks.com/topic/17765-date-stopped-working/#findComment-75916
Share on other sites

[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. ;)
Link to comment
https://forums.phpfreaks.com/topic/17765-date-stopped-working/#findComment-75925
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.