Jump to content

Creating New Record in Database


Recommended Posts

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 post
Share on other sites
  • 2 weeks later...

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.

Edited by Glorfindel
Link to post
Share on other sites

Same way as you print everything else out:

response.write(sql);

Link to post
Share on other sites

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 post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...