Jump to content

Problem inserting data into mySQL


Lee-yoshi

Recommended Posts

Hi!I'm trying the exercise on http://www.w3schools.com/ado/ado_add.asp and having a little problem.How do i insert data from an ASP variable into my mySQL table?

dim OrderedIDStrOrderedIDStr = 0Asql = "INSERT INTO replay_orders(Name,Address1,Address2,County,Country,Postcode,EMail,Tel,Order)"sql = sql & " VALUES "sql = sql & "('" & Request.Form( "Name" ) & "','" & Request.Form( "Add1" ) & "','" & Request.Form( "Add2" ) & "','" sql = sql & Request.Form( "County" ) & "','" & Request.Form( "Country" ) & "','" & Request.Form( "PostCode" ) & "','" sql = sql & Request.Form( "EMail" ) & "','" & Request.Form( "Tel" ) & "','" & OrderedIDStr & "')"

For some reason it all works except for the last part where i'm trying to insert a variable's value ('" & OrderedIDStr & "') and it's just having none of it.What's wrong with it? How do you send a variable over?(I'm aware it's probably the simplest little problem)Thanks to anyone who might be able to help :)

Link to comment
Share on other sites

For some reason it all works except for the last part where i'm trying to insert a variable's value ('" & OrderedIDStr & "') and it's just having none of it.
What exactly is the error message? I don't do a lot with VB, but I'm pretty sure this is not the correct way to assign a variable:OrderedIDStr = 0ABut, again, the server will tell you what the error is.
Link to comment
Share on other sites

Hi! Thanks for replying. Here's a tad more of my code:

Response.Write(OrderedIDStr)		sql = "INSERT INTO replay_orders(Name,Address1,Address2,County,Country,Postcode,EMail,Tel,Order)"sql = sql & " VALUES "sql = sql & "('" & Request.Form( "Name" ) & "','" & Request.Form( "Add1" ) & "','" & Request.Form( "Add2" ) & "','" sql = sql & Request.Form( "County" ) & "','" & Request.Form( "Country" ) & "','" & Request.Form( "PostCode" ) & "','" sql = sql & Request.Form( "EMail" ) & "','" & Request.Form( "Tel" ) & "','" & OrderedIDStr & "')"	on error resume nextDatabaseConnection2.Execute sql, recaffectedif err<>0 then	Response.Write("No Updating Done")else	Response.Write("Added")end if

It seems to be set ok, it prints out to screen correctly before it's used in the sql. However when i try and use the variable in the sql code ('" & OrderedIDStr & "') it also writes "No Updating Done" (I.e. there was an error and uses the 'if' statement above to write that out). If i take it out and just send the form's items it's fine and prints "Added" to screen.It's really baffling me! Hope you/someone can help!

Link to comment
Share on other sites

I removed the "on error resume next" line and recieved the error:

Microsoft OLE DB Provider for ODBC Drivers error '80040e14' [MySQL][ODBC 3.51 Driver][mysqld-5.0.77-log]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 'Order) VALUES ('thg','thth','thth','556y','tyh','dfvg','fg','jhuy7u','K9XZ')' at line 1

I've given it a good search and still can't produce any kind of answer. BTW i've just entered random combo's of letters & numbers into the form to test the entry values (Besides the last entry which has been changed to 'K9XZ'). I'm gonna kill myself if it's something ridiculously simple!! Any help appreciated :)

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...