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!

asp insert to mysql

Status
Not open for further replies.

krappleby025

Programmer
Sep 6, 2001
347
NL
Hi all, a quicky, i have never used mysql before, but i am getting an error on the following insert statement

query2 = "Insert into sitehits (id, month, year, " & daynum & ") values (" & test & ", " & month(date) & ", " & year(date) & ", " & sitehits & ") "

error is

Insert into sitehits (id, month, year, 21) values (0000007, 9, 2002, 1)
Microsoft OLE DB Provider for ODBC Drivers error '80040e09'

[TCX][MyODBC]You have an error in your SQL syntax near '21) values (0000007, 9, 2002, 1) ' at line 1

/menu.asp, line 123

NOTE their is also a insert write up on the page, to assist... any one HELP
 
Unless you have a field name 21, that is apossible error, and in fact I believe that is what the above error message is pointing at. It may not be legal to have a field name be numeric, so if you do have a field named 21 try changing it to d21 or something similar and see if that works.
-tarwn "The problem with a kludge is eventually you're going to have to back and do it right." - Programmers Saying (The Wiz Biz - Rick Cook)
"Your a geek!" - My Girlfriends saying
 
ok thanks i got rid of the error by changing the field name as you said, however i now have another proiblem,, the script works, but it is not placing the records into the database... ie

query2 = "Insert into sitehits (id, month, year, d" & daynum & ") values (" & test & ", " & month(date) & ", " & year(date) & ", " & sitehits & ") "

Generates


Insert into sitehits (id, month, year, d22) values (0000007, 9, 2002, 1)

and runs fine no errors, however when you go to the database, their is a new record., but the information is not their just a load of 0's

the fields are set as follows

id = int(11)
month = int(11)
year = int(11)
d22 = int(11)

and all i get is

0 0 0 0
 
Try inserting the same numbers without the 0's in front of the 7 for the id, it shouldn't make a differance but some db's are finicky that way. Another possibility is to rename month and year the same way you renamed your 21 field since month and year are generally built in functions and using them as field names may confuse the database as well.
I haven't used MySQL in 3 years, so if it isn't one of those two than I'll leave it to one of the MySQL experts around here to find what we're both missing :)
-Tarwn "The problem with a kludge is eventually you're going to have to back and do it right." - Programmers Saying (The Wiz Biz - Rick Cook)
"Your a geek!" - My Girlfriends saying
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top