Forum Moderators: open

Message Too Old, No Replies

ADO database integration

         

Blelisa

6:32 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



I think I figured out how to integrate with database with .asp now that I have done so I cannot get it too work. Whenever I try I get a 550-Internal Server Error.

Does anyone have any idea what I am doing wrong?
Below is my .asp code.
<%

set conn=Server.CreatePbject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "data/login2.mdb"

sql="UPDATE member SET "
sql=sql & "userid='" & Request.Form("userid") & "',"
sql=sql & "password='" & Request.Form("password") & "',"

on error resume next
conn.Execute sql
if err<>0 then
response.write("No update permissions!")
else
response.write("Record " & cid & " was updated!")
end if
end if
conn.close
%>
Any help would be greatly appreciated

txbakers

7:42 pm on Feb 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



first, you should go into the Tools > Internet Options > Advanced and turn off "show friendly HTTP error messages" so you can see the true error you are getting.

Then you'll be able to debug your code easier.

Blelisa

8:13 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



I have done what you asked, and made some changes and this is the error I receive now:

Microsoft VBScript compilation error '800a03ea'
This is now the error I am receiving
Syntax error

/demo_add.asp, line 12

connection.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0"\;Data Source=" &_

Here is my Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ language="VBScript" %>
<html>
<head>
<title>first asp</title>
</head>
<body>

<%

set conn=Server.CreateObject("ADODB.Connection")
connection.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0"\;Data Source=" &_
server.MapPath("data/login2.mdb")
connection.Open

sql="UPDATE member SET "
sql=sql & "userid='" & Request.Form("userid") & "',"
sql=sql & "password='" & Request.Form("password") & "'"

response.write(sql)
response.end

on error resume next
conn.Execute sql
if err<>0 then
response.write("No update permissions!")
else
response.write("Record " & cid & " was updated!")
end if
conn.close
%>
</body>
</html>

Easy_Coder

8:21 pm on Feb 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In the code from your 2nd post:

set conn=Server.CreateObject("ADODB.Connection")
connection.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0"\;Data Source=" &_
server.MapPath("data/login2.mdb")
connection.Open

You created an object called conn and then set a property and attempted to fire a method for an object that you did not create. That's going to generate an error.

Blelisa

8:31 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



That it did!

Blelisa

8:31 pm on Feb 15, 2005 (gmt 0)

10+ Year Member



Okay,
Thank you everyone for all of your help! I truly appreciate it as well as your patience. I finally got the .asp page recognized and no more errors. Now I get the error message that is in my code stating I do not have permissions. Here is code. Before I go fighting with my hoster, does it look like all my code is correct?

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ language="VBScript" %>
<html>
<head>
<title>first asp</title>
</head>
<body>

<%

Set connection = Server.CreateObject("ADODB.Connection")
connection.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &_
server.MapPath("data/login2.mdb")
connection.Open

sql="UPDATE member SET"
sql=sql & "userid='" & Request.Form("userid") & "',"
sql=sql & "password='" & Request.Form("password") & "'"

on error resume next
conn.Execute sql
if err<>0 then
response.write("No update permissions!")
else
response.write("Record " & cid & " was updated!")
end if
conn.close
%>
</body>
</html>

mattglet

1:13 pm on Feb 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You to make some spaces in your syntax:
sql="UPDATE member SET"
sql=sql & "userid='" & Request.Form("userid") & "',"
sql=sql & "password='" & Request.Form("password") & "'"

if you response.write(sql), you'll see that your statement actually looks like:
UPDATE member SETuserid='YourUserIDValue',password='YourPasswordValue'

So, do this instead:
sql="UPDATE member SET "
sql=sql & "userid='" & Request.Form("userid") & "', "
sql=sql & "password='" & Request.Form("password") & "'"

Note the added spaces at the end of the first 2 lines.

Added: instead of response.write("No update permissions"), do:
Response.Write(Err.Description)

This will show you the exact problem you're having while debugging.

Blelisa

2:20 pm on Feb 16, 2005 (gmt 0)

10+ Year Member



I have made those changes, in fact just did a copy and paste from your post. This is now the error I get:\

Syntax error in UPDATE statement.

Here is my code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ language="VBScript" %>
<html>
<head>
<title>first asp</title>
</head>
<body>

<%

Set connection = Server.CreateObject("ADODB.Connection")
connection.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &_
server.MapPath("data/login2.mdb")
connection.Open

sql="UPDATE member SET "
sql=sql & "username='" & Request.Form("username") & "',"
sql=sql & "password='" & Request.Form("password") & "'"

on error resume next
connection.Execute sql
if err<>0 then
Response.Write(Err.Description)
else
response.write("Record was updated!")
end if
connection.close
%>
</body>
</html>

Another thing I was wondering, should I be doing an update or an insert into command, or does it not make a difference?

Again, thanks for your help

mattur

2:40 pm on Feb 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



An UPDATE sql statement updates zero or more existing rows in a database.

An INSERT sql statement inserts one or more new rows into the database.

To check your sql, response.write it out as mentioned above, then create a new query in your Access database and paste the sql into it and test.

Blelisa

3:04 pm on Feb 16, 2005 (gmt 0)

10+ Year Member



Thank you, did as you suggested.
HEre is the sql that I got to operate in my database, however it is asking me for a username and password.
also when I do this is does not put my entries into the database it puts in zero's or negative ones.
Any thoughts?
Here is my sql
INSERT INTO member
VALUES (username='lisa', password='momma');

dotme

3:06 pm on Feb 16, 2005 (gmt 0)

10+ Year Member



You may need permissions set on the folder contining your mdb file. Anonymous visitors need write permissions to update an Access file.

mattur

3:37 pm on Feb 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Blelisa,

You're using UPDATE sql syntax in your INSERT statement. Change it to:

INSERT INTO member (username, password)
VALUES ('lisa', 'momma')

BTW you should also do a check or two on your passed Request.Form values. At the moment if someone puts a ' in the username or password field it will screw up your sql. You can protect against this by replacing a single apostrophe with two apostrophes:

strUsername = Request.Form("username")
strUsername = Replace(strUsername,"'","''")
etc

You may also want to check that the username and password are not blank, and/or are a minimum number of characters.
HTH

Blelisa

4:01 pm on Feb 16, 2005 (gmt 0)

10+ Year Member



Okay, tried everything, I have double checked with hosting company and all permissions have been unlocked, Have changed my syntax I think.
This is my code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ language="VBScript" %>
<html>
<head>
<title>first asp</title>
</head>
<body>

<%

Set connection = Server.CreateObject("ADODB.Connection")
connection.ConnectionString="Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &_
server.MapPath("data\login2.mdb")
connection.Open

sql="INSERT INTO member (username, password)"
sql=sql & "VALUES"
sql=sql & "('" & Request.Form("username") & "',"
sql=sql & "'" & Request.Form("password") & "')"

response.write(sql)

on error resume next
connection.Execute sql
if err<>0 then
Response.Write(Err.Description)
else
response.write("Record was updated!")
end if
connection.close
%>
</body>
</html>

This is my error:
INSERT INTO member (username, password)VALUES('try','again')Syntax error in INSERT INTO statement.

I just dont understand what is happening. I see from my sql that my form is passing the data I inputed. My syntax is telling it to insert into member table in the username and password columns. I am so frustrated. I think the hardest part is I do not understand the "syntax" of the code. ie-sql=sql, "'", etc

I have a feeling we are close to getting this figured out. I hope so!

dotme

4:32 pm on Feb 16, 2005 (gmt 0)

10+ Year Member



I think I might have the answer. A Google search returned a thread on another forum where it was indicated that in JET, the driver for Access, "password" is a reserved word. If this is true, you will want to change the NAME of the password field in your Access table (to pword, for example) and then update your ASP code to reflect that change.

If that's what the problem is, you should be all set after making that change.

Let us know?

mattur

5:05 pm on Feb 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Good catch dotme, I think you've solved the problem: "password" is a reserved word [office.microsoft.com] in Jet sql.

If you can't rename a field, it's possible to use reserved words by putting them in square brackets. eg change your sql to:

sql="INSERT INTO member (username, [password])"
...

mattglet

5:58 pm on Feb 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Very good catch dotme. Blelisa, also make sure your field types are correct in Access. Meaning: make sure you're not trying to insert a string into a number field, etc.

Blelisa

6:08 pm on Feb 16, 2005 (gmt 0)

10+ Year Member



DOTME YOU ROCK!
THAT WAS IT, IT WORKS!
Two whole days working on this and all it was, was a reserved word.
Thank You, Thank You, Thank You!