Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Database writing problem

Status
Not open for further replies.

Albuckj2

Programmer
Jan 7, 2003
68
0
0
GB
I can't seem to insert a record into my database from an ASP page. The code is listed below. I don't get a proper error, it just says "There is a problem with the page you are trying to reach and it cannot be displayed." I am giving the objConn object the adModeReadWrite mode property, so I thought this would mean to could write to the db? By the way, it's an access database residing on the server.
Maybe it is something to do with my hosting company? Or am I making a sily mistake???
I can successfully read stuff from the db, but this isn't working. Any ideas????


dim username, password, email, surname, first_name, organisation, date_joined

username = Request.Form("username")
password = Request.Form("password")
email = Request.Form("email")
surname = Request.Form("surname")
first_name = Request.Form("first_name")
organisation = Request.Form("organisation")
date_joined = now

dim objCon
set objConn = Server.CreateObject("ADODB.Connection")
DSN = "DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("db1.mdb") & ";"
' the Mode property to indicate the permissions on the connection
objConn.Mode = adModeReadWrite
objConn.Open(DSN)

' build up SQL string
strQ = "Select * From Users Where Username = '" _
& username & "' or Email = '" & email & "'"


' CREATE A RECORDSET OBJECT CALLED Recordset1
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
' CREATE A RECORDSET IDENTICAL TO THE DATABASE LINKED BY THE VARIABLE objConn
Set Recordset1.ActiveConnection = objConn

Recordset1.Open strQ, objConn, 0

dim reason
' IF IT IS NOT AT THE BEGINNING OR END OF FILE, THEN IT HAS FOUND A RECORD TO MATCH EITHER THE USERNAME OR EMAIL
if (not Recordset1.BOF) AND (not Recordset1.EOF) then
validated = "no"
for each x in Recordset1.Fields
if Recordset1("Username") = x.value then
if x.value = username then
reason = "username"
end if
elseif Recordset1("Email") = x.value then
if x.value = email then
reason = "email"
end if
end if
next
else
validated = "yes"
response.cookies("validated_user") = username
' BLANK INSERTS INTO THE DB CANNOT BE MADE
if surname = "" then
surname = " "
end if
if first_name = "" then
first_name = " "
end if
if organisation = "" then
organisation = " "
end if

sql = "INSERT INTO Users (Username, Password, Email, Surname, First_name, Organisation, Date_joined, Company_count) VALUES ('" & username & "', '" & password & "', '" & email & "', '" & surname & "', '" & first_name & "', '" & organisation & "', '" & date_joined & "', 0)"

objConn.Execute sql
end if
 
Hi,

have you set write permissions for the web server account on the folder that contains the database?

Digga

Sharing Knowledge Saves Valuable Time!
 
Albuckj2,

Most hosting companies do not provide asp as standard. It usually costs extra for asp if they can provide this service. Check this first.

moleboy
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top