Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with INSERT and DATE

Status
Not open for further replies.

ID10T16

Technical User
Sep 22, 2000
160
US
Ok, for some reason this won't work, but I'm almost certain that I had this way working before on another site I was testing.

Here's the error code (has the query string included):

A fatal MySQL error occured.
Query: INSERT INTO edit_log SET what='Staff member profile ID: #2 was changed', who='1118', how='First Name Changed from Old to New : Last Name Changed from Man to User', when= CURDATE()
Error: (1064) You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near 'when= CURDATE()' at line 1

I've tried typing the date myself (when='2007-01-04'), but I still get the error.

The when cell is set for DATE (default 0000-00-00).

Anybody have any idea?
 
Nevermind.

Apparently when is a reserved word.
 
as an FYI you don't need to use SET when you are doing an insert, just do one of two things:

1) if the values you are inserting match the number of columns you have AND they are being inserted in the order the columns appear in the table then all you need to do is:

Code:
insert into tablename values
('a',3,'good','bad',7)
for example.

IF you are inputting the values in different order OR you are not inserting all columns (perhaps you have default values or a timestamp column you don't need to insert into then use:

Code:
insert into tablename 
(columnA, columnC, columnD, columnF,columnH)
values
('a',3,'good','bad',7)
for example.
 
That's true, and I don't dislike that method, but I use SET because if there is an error, it's easier for me to see where it lies. The error system I use tells me exactly where the query comes apart, and that allows me to isolate the problem area and correct it. I'm not sure the method you are proposing is as conducing to easy debugging, but I could be wrong and it may be better. Thank you for your help though.
 
using standard sql is very conducive to easy debugging ;-)

if you keep using proprietary mysql syntax, you will have a real hard time when you go to work on some other database

INSERT with SET is not standard sql

r937.com | rudy.ca
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top