Syntax Error in ASP?

sub db_insert_edit_Users
sql = "INSERT INTO Users" & _
"(" & _
"user_name," & _
"password," & _
") VALUES (" & to_sql(user_name,"text") & "," & _
"" & to_sql(password,"text") & "," & _
""

on error goto 0
cn.Execute(sql)
if err.Number <> 0 then
b_error = true
error_list.add "db_insert_edit_Users" & err.Number ,"The database insert failed. " & err.Description
else
set rs = cn.Execute("SELECT @@IDENTITY")
user_id = rs(0)
rs.Close
msg_list.add "db_insert_edit_Users","The database insert was successful." end if
on error goto 0
end sub

It's from an appl that I got some time ago, so I didn't write it, but I see nothing wrong with the code. (But then, I'm not exactly proficient at ASP :p)
 
Are you sure this is the exact code that fails? It compiles fine on my machine. Though the first "On Error Goto 0" I'm sure should be "On Error Resume Next" (otherwise there is no point calling it).
For the first time, try to comment/remove all "On Error..." in this function and let's see what we'll get, since the code looks ok and runs smooth both on my local computer and on JodoHost site.
 
Get rid of the ON ERROR GOTO 0 crapola lines. Also, make sure to close the database connection at the end, even if there was an error. Use an If statement at the end to see if the connection is open, and if so, close it. That way it'll handle all cases... open or not.
-Dave
 
Hi,

I think it is missing bracket causing the problem.Try this

sql = "INSERT INTO Users(user_name,password) VALUES (" & to_sql(user_name, "text") & "," & to_sql(password, "text") & ")"

Mainly after the "Values(" the bracket is not closed. Since the compiler could not find the end of the statement so ends up at On error go to 0
 
asheshb said:
Hi,

I think it is missing bracket causing the problem.Try this

sql = "INSERT INTO Users(user_name,password) VALUES (" & to_sql(user_name, "text") & "," & to_sql(password, "text") & ")"

Mainly after the "Values(" the bracket is not closed. Since the compiler could not find the end of the statement so ends up at On error go to 0
Good one, though this is not the case. But anyway the closing bracket was missing. It won't cause compiler error though, since it is just a string. As I mentioned, I was able to compile successfully and run (untill crashed on database :) ) the code without single change on both my machine and JodoHost.
 
StPatrick said:
Good one, though this is not the case. But anyway the closing bracket was missing. It won't cause compiler error though, since it is just a string. As I mentioned, I was able to compile successfully and run (untill crashed on database :) ) the code without single change on both my machine and JodoHost.

You are right about the string. It would have given error while executing and not compiling.Actually I am in bad habit of seeing things ahead :)

So the only potential error left is

msg_list.add "db_insert_edit_Users","The database insert was successful." end if

Since "end if" is on the same line so compiler can not find the end of the If block
 
asheshb said:
You are right about the string. It would have given error while executing and not compiling.Actually I am in bad habit of seeing things ahead :)

So the only potential error left is

msg_list.add "db_insert_edit_Users","The database insert was successful." end if

Since "end if" is on the same line so compiler can not find the end of the If block
Ouch, you are right. As I remember, you have always add ":" between commands if you put them in same line, so this is the error... I probably formatted the code (as I always do) before checked it, that's why I've got no error :)
But looks like Bliss already solved the problem, since he is not answering, lol
 
Back
Top