Click to See Complete Forum and Search --> : Trouble with Username/Password Access Database


cflintten
02-19-2007, 03:28 AM
I am trying to set up a username and password database using Microsoft Access through an ASP form. I have a page where I can add administrators and users, but when I attempt to add one it comes to a page stating that I have an internal error. Here is my first page and my asp form:

<%Response.Buffer=TRUE%>
<%IF session("admin") = FALSE THEN Response.Redirect "admin.asp"%>
<html>
<head>
<title>Admin</title>
</head>
<body>
<table border="0" width="100%">
<tr>
<td width="33%" colspan="3" valign="bottom"><form method="POST" action="add.asp"><b><font size="2" face="Comic Sans MS">Add User</font></b></td>
</tr>
<tr>
<td width="33%"><font size="2" face="Comic Sans MS">Email Address<br>
<input type="text" name="T1" size="30"></font></td>
<td width="33%"><font size="2" face="Comic Sans MS">Password<br>
<input type="text" name="T2" size="20"></font></td>
<td width="34%" valign="bottom"><font size="2" face="Comic Sans MS">&nbsp;<br><input type="submit" value="Add User" name="B1"></font></td>
</tr>
<tr>
<td width="33%" colspan="3" valign="bottom"></form><form method="POST" action="add.asp"><b><font size="2" face="Comic Sans MS">Add Administrator</font></b></td>
</tr>
<tr>
<td width="33%"><font size="2" face="Comic Sans MS">Email Address<br>
<input type="text" name="T3" size="30"></font></td>
<td width="33%"><font size="2" face="Comic Sans MS">Password<br>
<input type="text" name="T4" size="20"></font></td>
<td width="34%" valign="bottom"><font size="2" face="Comic Sans MS">&nbsp;<br><input type="submit" value="Add Admin" name="B1"></font></td>
</tr>
<tr>
<td width="33%" colspan="3"><font size="2" face="Comic Sans MS"></form><a href="delete.asp?which=users"><b>Go
To Delete User</b></a></font></td>
</tr>
<tr>
<td width="33%" colspan="3"><a href="delete.asp?which=admin"><b><font size="2" face="Comic Sans MS">Go
To Delete Administrator</font></b></a></td>
</tr>
</table>

</body>

</html>




<%
'here is the connection string
Set conn = server.createobject("adodb.connection")
'this connection uses JET 4 it is the prefered method of connecting to an access database
DSNtemp = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("http://mypage.org/slog/login.mdb")
'if you cant use JET then comment out the line above and uncomment the line below
'DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" & Server.Mappath("/slog/login.mdb")
conn.Open DSNtemp

'here we are determining which form its from and getting the info from the form
'the first two represent the user form
'we will use this to add to the database
If Request.Form("T1") > "" Then
uid = Request.Form("T1")
pwd = Request.Form("T2")
Else
uid = Request.Form("T3")
pwd = Request.Form("T4")
End If

If Request.Form("T1") > "" Then
SQL = "Insert INTO users (uid,pwd) Values ('" & uid & "','" & pwd & "')"
Else
SQL = "Insert INTO admin (uid,pwd) Values ('" & uid & "','" & pwd & "')"
End If
Conn.Execute(SQL)
Conn.Close
Response.Redirect "admin2.asp"
%>


Any help would be greatly appreciated!

russell
02-19-2007, 09:07 AM
change
DSNtemp = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("http://mypage.org/slog/login.mdb")
to
DSNtemp = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.Mappath("/slog/login.mdb")
and change all of your string comparisons from > to <>

cflintten
02-19-2007, 10:32 PM
I made the changes that you suggested, so the form now looks like this:

<%
'here is the connection string
Set conn = server.createobject("adodb.connection")
'this connection uses JET 4 it is the prefered method of

connecting to an access database
DSNtemp = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &

Server.Mappath("/slog/login.mdb")
'if you cant use JET then comment out the line above and

uncomment the line below
'DSNtemp="DRIVER={Microsoft Access Driver (*.mdb)};DBQ=" &

Server.Mappath("/slog/login.mdb")
conn.Open DSNtemp

'here we are determining which form its from and getting the

info from the form
'the first two represent the user form
'we will use this to add to the database
If Request.Form("T1") <> "" Then
uid = Request.Form("T1")
pwd = Request.Form("T2")
Else
uid = Request.Form("T3")
pwd = Request.Form("T4")
End If

If Request.Form("T1") <> "" Then
SQL = "Insert INTO users (uid,pwd) Values ('" & uid &

"','" & pwd & "')"
Else
SQL = "Insert INTO admin (uid,pwd) Values ('" & uid &

"','" & pwd & "')"
End If
Conn.Execute(SQL)
Conn.Close
Response.Redirect "admin2.asp"
%>


However, I am still getting a page saying that I have an internal error. Is there anything else that I would need to fix?

Thanks,
cflintten

russell
02-19-2007, 10:58 PM
what line is the error occurring on?

cflintten
02-19-2007, 11:30 PM
Sorry for the inconvienance...

I did some research and my problem was that my hosting company had set the permissions for my access database in a specific folder. When I switched my references to the right folder, it worked fine.

Thanks for your thoughtful help and patience!

cflintten

russell
02-19-2007, 11:32 PM
Glad you got it working! :)