I have a problem that is making me insane... I have a page with check-boxes, text-fields and date-fields. I usually create the basics in Dreamweaver CS3 first and edit the SQL-codes afterwards, because I write one session to two tables (logging). Anyway... I attached my entire page here. Please tell me whyyyyyyyyyyy I get this error:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[MySQL][ODBC 5.1 Driver][mysqld-5.0.51b-community-nt]Incorrect date value: '' for column 'mmm_behandling_hyperterm_tnfalfa_dato' at row 1
/melanom/melanom_onstudy2.asp, line 139
when I either update an existing record or create a new record AND in either case the four date-fields has no value???? It works fine with the normal Dreamweaver-codes, and it used to work on a lot of other forms I made with the modified SQL-codes. But somehow I must have made something wrong. I just can't figure out what...
Please HEEEEEEELP!!!!
I use classic asp and MySQL.
Also you could test to see if the value in the post data is null and then alter your update or insert statement?
Please run the following command on the mysql console and send post the result.
SHOW CREATE TABLE tbl_onstudy2\G
ullenulle
ASKER
Hi. Thanks for your response. I ran your command, and this is the result:
#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 '\G' at line 1
I guess you expected something else? :o)
Yes, I allow NULL for all date-variables. When I create a new record and I entered a date for all date-variables, then it works fine. But if some or all is empty, then I get the error. Also if I make a date-variable empty in an existing date-variable, then I get the error.
When I create or edit records in phpmyadmin (the console), then I can do anything I want to. And if I remove the date-variables in the SQL-codes, then no problems either... It's something with those stupid date-variables...
Best regards
Ullenulle
Steve Tempest
Hi,
If the value in the form is empty try making the value 'NULL' instead of just blank...
Can you print the update statement to the screen and paste here for me so we can try a few things?
Also try running that command again without the \G on the end of it...
If the field is empty, then it will enter "NULL" into the table. It worked fine so far in other of my databases, but for some reason not now... :-(
Can't you see all the code in my page? I added it to this question. The SQL UPDATE statement is line 137.
Best regards
Ullenulle
Steve Tempest
Can you send me the update statement that fails please? So that I can see exactly what is passed to the ODBC... I don't have an ASP server to test your code on. And yes I've read line 137.
ullenulle
ASKER
Hi again.
This is the UPDATE-statement, that fails when a date-value isn't entered:
in your asp can you set it so that before it executes the insert and update it prints the value of
sSQL_update and sSQL to the page and copy and paste that...
So you go in and alter the form and then hit submit and have it print the update statement to the screen and paste that here... as everything in the above example is empty.
The reason I ask is that I have setup your table in my database and I'd like to try the exact same update statement that you are passing to the ODBC on the mysql console.
So if you can provide a fully populated insert statement and then an update statement that updates the insert that would be good.
In your error message it says
Incorrect date value: '' for column mmm_behandling_hyperterm_tnfalfa_dato
and if the value of mmm_behandling_hyperterm_tnfalfa_dato is 'NULL' (type string)
The error would read
Incorrect date value: 'NULL' for column mmm_behandling_hyperterm_tnfalfa_dato
ullenulle
ASKER
Hi again.
Ok... I made a response.write before the code is executed. INSERT-error first:
[MySQL][ODBC 5.1 Driver][mysqld-5.0.51b-community-nt]Incorrect date value: '' for column 'mmm_behandling_hyperterm_tnfalfa_dato' at row 1
/melanom/melanom_onstudy2.asp, line 143
Is that what you're looking for?
Best regards
Ullenulle
ullenulle
ASKER
Aha... I read the response.write now for the first time. :o) It seems that the problem is, that my asp-code doesn't pass the "NULL" on to the database... do you agree??
Let's take for example this date-field:
How should I make it different to pass the NULL on to the database in stead of an empty '' ? And how comes it's a problem now even though I used this code many times before with no problem??
Try altering your asp so that NULL is double quoted.
Also what version of mysql is the server?
Steve Tempest
both of those insert and update statements worked for me using the console... so I'm wondering if it's something to do with the ODBC where it doesn't like the values being empty....
I thought that maybe asp suddenly evaluated an empty field as if there's a value... but no change...
It's MySQL 5.1 (Serverversion: 5.0.51b-community-nt). In my connectionstring I have: DRIVER={MySQL ODBC 5.1 Driver} and it works fine with all other databases of mine. I tried changing to 3.51, but the problem is still there... This is just too weird!!!! any other ideas?? :-)
Best regards
Ullenulle
Steve Tempest
Well, I would try hard coding the insert and update statements with the NULL in place and see if it works... then we just need to work out how to swap out the variable... with null it should not be quoted at all... the example above I posted is wrong as I have it single quoted.
if NULL wont work try '0000-00-00' instead from what I've read the ODBC will swap it out with NULL on execution.
I just found this post also... which confirm to me that it's likely that we need the word NULL and not empty single quotes...
ullenulle
ASKER
Ok... do we agree that I need to edit the date-variables before they are being passed on to the database? But asp takes single-quotes as a remark... How should I try the 0000-00-00 regarding quotes? I actually tried it a while ago without quotes and with double quotes. Any tricks?
Yes you need to check the variables and ensure they have a value. Is it possible to set the default value of the date input to 0000-00-00 so if not selected by the user then it will pass that value?
alternatively you would need to test if the date-variables are indeed valid and if not set the variable to 0000-00-00.
In the insert and update statement the 0000-00-00 needs to be single quoted like you have done for the other dates.
Sorry I'm not familiar with asp at all so cant be a huge help there... above is what I would do in perl...
Maybe try an if statement (i'm guessing so this code probably wont work...)
dato2 = Request.Form("mmm_behandling_hyperterm_tnfalfa_dato2")
dato2_len = len(dato2)
If(dato2_len == 0) Then
xmmm_behandling_kirurgi_dato2="0000-00-00"
Else
xmmm_behandling_kirurgi_dato2=dato2
End If
ullenulle
ASKER
I'll try to create some other code for the asp-part of the page. What's your conclusion? Is it an asp or MySQL problem? So far I guess it's more a problem with asp and/or the webserver... or the way my code is dealt with on the server. The "fun" part is, that it worked in other of my databases so far... so weird....
Steve Tempest
I think it could be a limitation of the version of the ODBC you are using. You could try updating it to a newer version. The reason I think this is that the sql you provided above with the single empty sql quotes executes on my mysql database just fine from the mysql console.
Hmmm... doesn't the ODBC version in my connectionstring refer to the database-server on my webhotel? If I update the ODBC, wouldn't that only affect my own computer?
I'll dig into that tomorrow. I'm away for a day. :-)
Best regards
Ullenulle
ullenulle
ASKER
Hey! Thank you so much! This was the solution to my annoying problem! My webhotel gave the user I created some "SUPER privilege". After that I was able to use this setting in my SQL-codes before executing any INSERT og UPDATE statements:
sessionSQL = "SET SESSION sql_mode = 'ALLOW_INVALID_DATES'"
objConn.execute(sessionSQL)
So finally my database will "eat" NULL in the date-fields. I just can't understand that the problem didn't occur untill now... weird... but main thing is that it works again now! Thank you again for guiding me in the right direction. :-)
Also you could test to see if the value in the post data is null and then alter your update or insert statement?
Please run the following command on the mysql console and send post the result.
SHOW CREATE TABLE tbl_onstudy2\G