Striped Fish2 Posted February 17, 2011 Share Posted February 17, 2011 I'm having an issue adding a record to a database. I double checked the fieldnames but they are all correct I'm thinking one of my fields could possibly be a keyword but I am not sure. Oh and experience is meant to be spelled wrong because I was lazy when I originally created the table and now have so many pages that use that field name that I don't feel like changing it. Here is my code. <%set conn=Server.CreateObject("ADODB.Connection") conn.provider="Microsoft.Jet.OLEDB.4.0"conn.open "C:\inetpub\wwwroot\DragonKwest.mdb"name=Request.Querystring("name")race=Request.Querystring("race")gender=Request.Querystring("gender")ID=Request.cookies("ID")sql="INSERT INTO Characters ([Name],[Acc],Race,[Turns],[Gold],[lvl],Gender,[HP],Hitpoints,[num_of_kills],[Portrait],"sql=sql & "expierence,[XP],energypoints,[EP],att1,att2,[STR],[RAN],[H2H],[MGR],[DODGE],[PARRY],[ARMOUR],lsp,"sql=sql & "[equipaccessory],[Date_Registered],[last-logged],[equipbow],[equipsword])" sql=sql & " VALUES "sql=sql & "('" & name & "'," & ID & ",'" & race & "',50,200,1,'" & gender & "',25,25,0,'images/Portraits/elf-male.png',"sql=sql & "0,20,10,10,'Strong Shot','Broad Attack,18,93,60,38,83,55,0,'dragoth/tutorial.asp',"sql=sql & "'empty',#" & NOW() & "#,#" & NOW() & "#,'empty','empty')"on error resume nextconn.Execute sqlconn.close%> Thanks in advance for any help you can give Link to comment Share on other sites More sharing options...
Striped Fish2 Posted March 1, 2011 Author Share Posted March 1, 2011 Anyone have any solution? Link to comment Share on other sites More sharing options...
justsomeguy Posted March 1, 2011 Share Posted March 1, 2011 This is the list of reserved words in Access:http://support.microsoft.com/kb/286335Why are you using "on error resume next"? You're basically telling the server to ignore errors, including error messages. If there's an error, don't you want to know about it? Link to comment Share on other sites More sharing options...
Striped Fish2 Posted March 2, 2011 Author Share Posted March 2, 2011 Okay I looked through the list of reserved words and none of them matched what I had so I am good there. Then I removed "on error resume next". Now I have added an error if statement. Here is my code: <%set conn=Server.CreateObject("ADODB.Connection") conn.provider="Microsoft.Jet.OLEDB.4.0"conn.open "C:\inetpub\wwwroot\DragonKwest.mdb"name=Request.Querystring("name")race=Request.Querystring("race")gender=Request.Querystring("gender")ID=Request.cookies("ID")sql="INSERT INTO Characters ([Name],[Acc],Race,[Turns],[Gold],[lvl],Gender,[HP],Hitpoints,[num_of_kills],[Portrait],"sql=sql & "expierence,[XP],energypoints,[EP],att1,att2,[STR],[RAN],[H2H],[MGR],[DODGE],[PARRY],[ARMOUR],lsp,"sql=sql & "[equipaccessory],[Date_Registered],[last-logged],[equipbow],[equipsword])" sql=sql & " VALUES "sql=sql & "('" & name & "'," & ID & ",'" & race & "',50,200,1,'" & gender & "',25,25,0,'images/Portraits/elf-male.png',"sql=sql & "0,20,10,10,'Strong Shot','Broad Attack,18,93,60,38,83,55,0,'dragoth/tutorial.asp',"sql=sql & "'empty',#" & NOW() & "#,#" & NOW() & "#,'empty','empty')"conn.execute sqlif err<>0 then for each objErr in objConn.Errors response.write("<p>") response.write("Description: ") response.write(objErr.Description & "<br />") response.write("Help context: ") response.write(objErr.HelpContext & "<br />") response.write("Help file: ") response.write(objErr.HelpFile & "<br />") response.write("Native error: ") response.write(objErr.NativeError & "<br />") response.write("Error number: ") response.write(objErr.Number & "<br />") response.write("Error source: ") response.write(objErr.Source & "<br />") response.write("SQL state: ") response.write(objErr.SQLState & "<br />") response.write("</p>") nextelse Response.Write("Success!")end ifconn.close%> The issue is that is now it returns nothing. And doesn't add any records to the database. Link to comment Share on other sites More sharing options...
justsomeguy Posted March 2, 2011 Share Posted March 2, 2011 What happens if you print that query out before running it? Link to comment Share on other sites More sharing options...
Striped Fish2 Posted March 2, 2011 Author Share Posted March 2, 2011 Sorry I am kind of new to server side scripting. So I apologize if my question sounds silly, but how do you do that? Link to comment Share on other sites More sharing options...
Synook Posted March 3, 2011 Share Posted March 3, 2011 Same way as you print everything else out: response.write(sql); Link to comment Share on other sites More sharing options...
Striped Fish2 Posted March 3, 2011 Author Share Posted March 3, 2011 Oh that's what you mean. Okay I did that and it returns this: INSERT INTO Characters ([Name],[Acc],Race,[Turns],[Gold],[lvl],Gender,[HP],Hitpoints,[num_of_kills],[Portrait],expierence,[XP],energypoints,[EP],att1,att2,[STR],[RAN],[H2H],[MGR],[DODGE],[PARRY],[ARMOUR],lsp,[equipaccessory],[Date_Registered],[last-logged],[equipbow],[equipsword]) VALUES ('TestCharacter','Elf',50,200,1,'Male',25,25,0,'images/Portraits/elf-male.png',0,20,10,10,'Strong Shot','Broad Attack,18,93,60,38,83,55,0,'dragoth/tutorial.asp','empty',#3/3/2011 4:30:37 PM#,#3/3/2011 4:30:37 PM#,'empty','empty') I noticed there was an extra comma for some reason. I can't remove it because it isn't in the code <%set conn=Server.CreateObject("ADODB.Connection") conn.provider="Microsoft.Jet.OLEDB.4.0"conn.open "C:\inetpub\wwwroot\DragonKwest.mdb"name=Request.Querystring("name")race=Request.Querystring("race")gender=Request.Querystring("gender")ID=Request.cookies("ID")sql="INSERT INTO Characters ([Name],[Acc],Race,[Turns],[Gold],[lvl],Gender,[HP],Hitpoints,[num_of_kills],[Portrait],"sql=sql & "expierence,[XP],energypoints,[EP],att1,att2,[STR],[RAN],[H2H],[MGR],[DODGE],[PARRY],[ARMOUR],lsp,"sql=sql & "[equipaccessory],[Date_Registered],[last-logged],[equipbow],[equipsword])" sql=sql & " VALUES "sql=sql & "('" & name & "'," & ID & ",'" & race & "',50,200,1,'" & gender & "',25,25,0,'images/Portraits/elf-male.png',"sql=sql & "0,20,10,10,'Strong Shot','Broad Attack,18,93,60,38,83,55,0,'dragoth/tutorial.asp',"sql=sql & "'empty',#" & NOW() & "#,#" & NOW() & "#,'empty','empty')"response.write sqlconn.Execute sqlif err<>0 then for each objErr in objConn.Errors response.write("<p>") response.write("Description: ") response.write(objErr.Description & "<br />") response.write("Help context: ") response.write(objErr.HelpContext & "<br />") response.write("Help file: ") response.write(objErr.HelpFile & "<br />") response.write("Native error: ") response.write(objErr.NativeError & "<br />") response.write("Error number: ") response.write(objErr.Number & "<br />") response.write("Error source: ") response.write(objErr.Source & "<br />") response.write("SQL state: ") response.write(objErr.SQLState & "<br />") response.write("</p>") nextelse Response.Write("Success!")end ifconn.close%> Link to comment Share on other sites More sharing options...
justsomeguy Posted March 3, 2011 Share Posted March 3, 2011 I don't see an extra comma, but I see a missing quote after "Broad Attack". Link to comment Share on other sites More sharing options...
Striped Fish2 Posted March 3, 2011 Author Share Posted March 3, 2011 Okay I figured out the comma issue. And thanks for telling me about the missing quote. I tried it now and it works. Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.