bschave2
asked on
can someone help me solve these errors
I am getting errors for this particular form I am developing for registration that will eventually go to a admin area. I need help solving these errors. I get an error 500 telling me variable undefined and also error 424 object required.
Here is the code:
Here is the code:
<%
Option Explicit
Dim strError, strSQL
'see if the form has been submitted
If Request.Form("action")="register" Then
'the form has been submitted
'// validate the form
'check if a username has been entered
If Request.Form("username") = "" Then _
strError = strError & "- Please enter a username<br>" & vbNewLine
'check if a password has been entered
If Request.Form("password") = "" Then _
strError = strError & "- Please enter a password<br>" & vbNewLine
'check if the passwords are the same... but don't display it if the password field is blank.
If Request.Form("password") <> Request.Form("password_confirm") _
And Request.Form("password") <> "" Then _
strError = strError & "- Your passwords do not match<br>" & vbNewLine
'// check if an error has occured
If strError = "" Then
'continue
'include database connection code
%>
<!--#include file="ETPRoutines.asp"-->
<%
On Error Resume Next
'// create the SQL
strSQL = "INSERT INTO members ([username],[password]) VALUES " & _
"('" & fixQuotes(Request.Form("username")) & "','" & _
fixQuotes(Request.Form("password")) & "')"
'// run the SQL
objConn.Execute strSQL
'// check for an error
'// ATTENTION: this should be changed depending on the database provider
If Err.Number = -500 Then
strError = "- That username is already in use. Please choose another<br>" & vbNewLine
ElseIf Err.Number <> 0 Then
strError = "- An error occured. " & Err.Number & " : " & _
Err.Description & "<br>" & vbNewLine
Else
'record created... redirect
Response.Redirect "login.asp?msg=" & Server.URLEncode("Thank you for registering")
Response.End
End If
'restore standard error handling
On Error Goto 0
End If
If strError <> "" Then
'output the error message
'add extra HTML...
strError = "<p><font color=""#FF0000"">The following errors occured:" & _
"</font><br>" & vbNewLine & strError
End If
End If
Function fixQuotes(strData)
fixQuotes = Replace(strData,"'","''")
End Function
%>
<html>
<head>
<title>My Website's Registration Page</title>
</head>
<body>
<h1>Member Registration</h1>
<p>Please fill out the following form to register as a member, and
gain access to our members area.</p>
<%=strError%>
<form action="register.asp" method="POST">
<input type="hidden" name="action" value="register">
<table border="0">
<tr>
<td><b>Username</b></td>
<td><input type="text" maxlength=20 name="username"
value="<%=Server.HTMLEncode(Request.Form("username"))%>"></td>
</tr>
<tr>
<td><b>Password</b></td>
<td><input type="password" maxlength=20 name="password"
value="<%=Server.HTMLEncode(Request.Form("password"))%>"></td>
</tr>
<tr>
<td><b>Password Confirm</b></td>
<td><input type="password" maxlength=20 name="password_confirm"
value="<%=Server.HTMLEncode(Request.Form("password_confirm"))%>"></td>
</tr>
<tr>
<td> </td>
<td><input type="submit" value="Complete Registration"></td>
</tr>
</table>
</form>
</body>
</html>
Looks like you never declared declared fixQuotes
ASKER
that wasn't it, it's a function and if i try to define, it will say it's redefined.
ASKER
I think that strData is not defined, am I right?
That is also not defined. try defining that and see what happens. Often times if the error is not obvious, trial and error is never a bad approach. If you remove option explicit, do you receive any errors?
ASKER
I removed that a long time ago and got 424, but put it back in.
Was the error the same when you defined strData?
ASKER
yep.
hmm, any chance there could be an undeclared variable or problem with your include file or DB variable names like objConn?
ASKER
Nope that is not it. I just checked.
I am able to replicate the 500 error but this is because I removed the #include directive since I do not have that file. Basically I get the blank form and I can submit and gives me the appropriate error messages if I leave fields blank, but when I complete the form I get the 500 error message.
I was able to pinpoint the problem by commenting out:
'On Error Resume Next
That way the script will crash at the exact location where the error occurs and the server will give you details about the error. At least during development time you should have the above line commented out to pinpoint the problems. Last time I has helping someone else, I noticed the IE was not giving details about the problem (line #, etc) but Firefox did. Something to keep in mind.
I was able to pinpoint the problem by commenting out:
'On Error Resume Next
That way the script will crash at the exact location where the error occurs and the server will give you details about the error. At least during development time you should have the above line commented out to pinpoint the problems. Last time I has helping someone else, I noticed the IE was not giving details about the problem (line #, etc) but Firefox did. Something to keep in mind.
ASKER
that worked, but now i get an error telling me Microsoft VBScript runtime (0x800A01A8)
Object required: ''
Object required: ''
ASKER
do I need to add a rs?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
you were right, but it was also the code...it was the code that was telling the include file to be pulled. It was missing a connection variable and the rsobj.
OK. In the future, always initialize your variables. Having set
strError=""
from the beginning would have helped ensure the asp file was included. Also, there is no way I could have figured out rsobj with the posted code since there is no reference to it. Glad it worked out.
strError=""
from the beginning would have helped ensure the asp file was included. Also, there is no way I could have figured out rsobj with the posted code since there is no reference to it. Glad it worked out.
Forced accept.
Computer101
EE Admin
Computer101
EE Admin