Mysql curdate() not working

When I add a record to the DB, I want the current date (in 0000-00-00 format) written to one of the fields. The field/column is of type “date” and correctly stores dates in this format if I manually insert their values. However, when I use the curdate() function, a date of 0000-00-00 is inserted instead. Here’s the INSERT:


$sql = "INSERT INTO Clients (ID, ContactName, Title, CompanyName, Address, Phone, Extension, Fax, Email, Website, InboundBox, OutboundBox, ProvideListBox, BothBox, InboundCalls, OutboundCalls, InboundMinutes, OutboundMinutes, SalesBox, AppointmentBox, LeadBox, MarketBox, CustomerServiceBox, CustomerRetentionBox, DatabaseBox, Other, BusinessBox, Titles, ConsumerBox, Begin, End, OngoingBox, Service, Budget, Comments, AddDate)
    VALUES ('$ID', '$ContactName', '$Title', '$CompanyName', '$Address', '$Phone', '$Extension', '$Fax', '$Email', '$Website', '$InboundBox', '$OutboundBox', '$ProvideListBox', '$BothBox', '$InboundCalls', '$OutboundCall', '$InboundMinutes', '$OutboundMinutes', '$SalesBox', '$AppointmentBox', '$LeadBox', '$MarketBox', '$CustomerServiceBox', '$CustomerRetentionBox', '$DatabaseBox', '$Other', '$BusinessBox', '$Titles', '$ConsumerBox', '$Begin', '$End', '$OngoingBox', '$Service', '$Budget', '$Comments', 'CURDATE()')";

I also tried using the web mySQL client I have access to, to set the field to “curdate” as the client said I was doing and got the following… not as important if I can fix the above:

SQL-query :

UPDATE Clients SET AddDate = CURDATE(‘0000-00-00’) WHERE ID = ‘2’ LIMIT 1;

MySQL said:

You have an error in your SQL syntax near ‘‘0000-00-00’) WHERE ID = ‘2’ LIMIT 1’ at line 1

Thanks in advance for any help!

in your INSERT, the problem is you have quotes around CURDATE(). so you’re inserting the string “CURDATE()” into your date column, which isn’t a valid date, so it’s converted to its default value: 0000-00-00. so remove the quotes.

the problem in your UPDATE is that CURDATE doesn’t take a parameter. also, since ID is a number, you shouldn’t put quotes around its value in the query. (sigh all this automatic quoting of everything :frowning: :)) the UPDATE should look like this:

UPDATE `Clients` SET `AddDate` = CURDATE() WHERE `ID` = 2 LIMIT 1;

Originally posted by DR_LaRRY_PEpPeR
[B](sigh all this automatic quoting of everything :frowning: :))

 [/B]


LOL :p

DR_LaRRY_PEpPeR,

Thanks for the help. Funny thing is that UPDATE was the query generated by the web mysql client the host (Interland - a major hosting company) provides all its clients. It has drop down boxes of values you can put into a field, when I chose CURDATE it wrote out that string…

Thanks again :slight_smile:

hmm, that is weird. :slight_smile: