ASP Database Updating Errors

Ive been working on a simple data base on my IIS and have created a funtional login system. However when I went to create a sign up site for my page I keep getting errors. This is my text. All errors end up around were im attempting to edit it and add a new user.
Text:
<% option explicit %>

<html>

<!--#include virtual="/login/adovbs.inc"-->
<head>
<title>TESTING HTML-ASP</title>
<style type="text/css">
a.a:link {color=#000000}
a.a:visited {color=#000000}
a.a:hover {color=#3300CC}
h1 {font-family: Crass;font-size: 350%}
h3 {font-family: Crass;font-size: 200%}
</style>
</head>

<body bgcolor="#696969">

<table cellpadding="4" border="1" bgcolor="#708090">
<tr>
<td align="center" width="832"><h1>TESTING HTML-ASP</td>
</tr>
</table>
<div align="center">
<table cellpadding="4" border="1" align="left" bgcolor="#808080">
<tr>
<td width="100" height="600" align="center" valign="top">
<b>Links:</b><br>
<a href="http://localhost/asp/helloworld.asp" class="a">Hello World</a><br>
<a href="http://localhost/asp/cost+tax.asp" class="a">Cost+Tax</a><br>
<a href="http://localhost/asp/date.asp" class="a">Date</a><br>
<a href="http://localhost/asp/strings.asp" class="a">Strings</a><br>
<a href="http://localhost/asp/strings2.asp" class="a">Strings2</a><br>
<a href="http://localhost/asp/fontsize.asp" class="a">Font Size</a><br>
<a href="http://localhost/asp/daynumber.asp" class="a">Day Number</a><br>
<a href="http://localhost/asp/random.asp" class="a">Random #</a><br>
<a href="http://localhost/asp/testingtxt.asp" class="a">Test Txt</a><br>
</td>
</td>
</tr>
</table>
<table cellpadding="4" border="1" align="left">
<tr>
<td width="600" height="600" valign="top">
<% dim a
a=0%>

<% if request.form("user")="" and request.form("pass1")="" and request.form("pass2")="" and request.form("email")="" or request.form("pass1")<>request.form("pass2") then %>
<% a=a+1 %>
<h3>Sign Up</h3><br>
<% if a<>1 then%><b>Error: You did not fill in all of the form properly.</b><br><%else%>
It is very easy to sign up to our secure server so that you can test you asp scripts.<br>
Just fill out the form below and you will be one step closer to becoming a testing site member.<br>
<form action="createnew.asp" method="post">
User Name:<center><input type="text" name="user"></center>
Password:<center><input type="password" name="pass1"></center>
Verify Password:<center><input type="password" name="pass2"></center>
Email:<center><input type="text" name="email"><br><br>
<a href="agreement.asp" class="a">Rules and Regulations</a><br><br>
<input type="submit" value="I Agree to the Rules and Regulations"></form>
<form action="noagreement.asp" method="post"><input type="submit" value="I Do Not Agree">
</form>
<% end if %>
<% else
dim connect, info, query

set connect=server.createobject("ADODB.Connection")
connect.open "info"
set info=server.createobject("ADODB.Recordset")

query= "SELECT * FROM info " _
& "WHERE User='" & Replace(Request.Form("user"), "'", "''") & "' "

info.open query, connect, adOpenDynamic, adLockOptimistic, adCmdText


'here is were the error occures*******************************


if info.EOF then

info.addnew
info("User")=request.form("user")
info("Password")=request.form("pass1")
info("Email")=request.form("email")
info.update

else %>
This user is already taken. Please think of a new username and fill out the
<a href="createnew.asp" class="a">form</a>.

<% end if %>
<% end if %>
</td>
</tr>
</table>
<table cellpadding="4" border="1" align="left" bgcolor="#808080">
<tr>
<td width="100" height="600" valign="top">
</td>
</tr>
</table>
</div>

</body>

</html>

Thanks for taking a look and hope u can find whats bugging it.
 
This line jumps out at me:

connect.open "info"

You are trying to open a connection using a variable, but you have it surrounded with double quotes.

Mark
 
Hummm......
I have been modleing my script after ASP for Dummies and that is they way that they make the connection. I have used this other times and it has worked so I dont think that is the problem.
 
OK, let's try something else.

Can you be more specific about the error? What error are you getting? What line? Any more info could greatly help.

Mark
 
You may use this example I made as a pattern. Just add the necessary client-side and server-side validation scripts, as well as modify filenames and the like:


(registration-form.html)
Code:
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Registration Form</title>
<script type="text/javascript">
<!--
function checkregistrationform() {
	if (document.getElementById("uidbox").value == "") {
		alert("Please provide a user ID.")
		document.getElementById("uidbox").focus()
		return false
	} else if (document.getElementById("pwdbox").value == "") {
		alert("Please provide a password.")
		document.getElementById("pwdbox").focus()
		return false
	} else {
		return true
	}
}
//-->
</script>
</head>
<body>
<form action="registration-script.asp" method="POST" onsubmit="return checkregistrationform();">
<div>User ID: <input type="text" size="20" maxlength="20" id="uidbox" /></div>
<div>Password: <input type="password" size="20" maxlength="20" id="pwdbox" /></div>
<div><input type="submit" value="Create Account" /></div>
</form>
</body>
</html>


(registration-script.asp)
Code:
<% @Language="VBScript" %>
<% Option Explicit %>
<%
On Error Resume Next

Dim CN, RS
Dim CNstr
Dim DBrelpath
Dim uidval, pwdval
Dim haserror, uidexists

'RETRIEVE FORM DATA
If Trim(Request.Form("uidbox")) <> "" And Trim(Request.Form("pwdbox")) <> "" Then
	uidval = Replace(Replace(Request.Form("uidbox"),"'",""), """", "")
	pwdval = Replace(Replace(Request.Form("pwdbox"),"'",""), """", "")
Else
	Response.Redirect("registration-form.html")
End If

'INITIALIZE VARIABLES
haserror = False
DBrelpath = "yourdb.mdb"

'CREATE INSTANCE OF ADODB.CONNECTION
Set CN = Server.CreateObject("ADODB.Connection")

'USE LINE BELOW IF USING A DSN
'CN.ConnectionString = "DSN=yourdsn;"

'USE LINE BELOW IF NOT USING DSN
CN.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(DBrelpath) & ";"

'OPEN CONNECTION
CN.Open

'CHECK FOR ERROR
If Err.Number <> 0 Then
	Set CN = Nothing
	Response.Redirect("servererror.html")
End If

'CREATE INSTANCE OF ADODB.RECORDSET
Set RS = Server.CreateObject("ADODB.RecordSet")

'DEFINE PROPERTIES AND CALL METHODS OF RECORDSET
With RS
	'SERVER-SIDE CURSORS
	.CursorLocation = 2

	'OPTIMISTIC LOCKING
	.LockType = 3

	'DEFINE CONNECTION TO USE
	Set .ActiveConnection = CN

	'ASSOCIATE TABLE TO RECORDSET
	.Source = "Users"

	'OPEN RECORDSET
	.Open()

	'CHECK FOR ERROR
	If Err.Number <> 0 Then
		haserror = True
	Else
		'ATTEMPT TO FIND THE SELECTED UID
		.Find "uid='" & uidval & "'"

		'CHECK IF UID INDEED EXISTS
		If Not .EOF Then
			uidexists = True
		Else
			'CREATE NEW ROW
			.AddNew()

			'DEFINE FIELD VALUES
			.Fields("uid") = uidval
			.Fields("pwd") = pwdval

			'WRITE CHANGES
			.Update()

			'CHECK FOR ERROR
			If Err.Number <> 0 Then
				haserror = True
			End If
		End If

		'CLOSE RECORDSET
		.Close()
	End If
End With

'DESTROY OBJECT
Set RS = Nothing

'CLOSE CONNECTION
CN.Close()

'DESTROY OBJECT
Set CN = Nothing

'CHECK IF UID EXISTS
If uidexists Then
	Response.Redirect("chooseanotheruid.html")
End If

'CHECK FOR ERROR
If haserror Then
	Response.Redirect("servererror.html")
End If

'REGISTRATION SUCCESSFUL
Response.Redirect("registration-successful.asp")
%>
 
By the way, I assumed that you are using a Microsoft Access Database. Obviously, the script would have been a lot better (like allow ' and " in the password and other fields) if you:

  • have pre-built queries in MS Access that can accept parameters to perform registration routines, or
  • used MS SQL Server 2000 and created stored procedures in it
 
i think i deleted the page because i didnt think anyone was going to respond to my post. well ill just have to base it off some other script. thanks though.
 
Back
Top