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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Checking for duplicate usernames error 3

Status
Not open for further replies.

gchaves

Programmer
Oct 27, 2003
105
US
Greetings!

I am building an application where users can log in to view a directory and manage their own user information. The user's information is added to the database via a web form which is not password protected (client request). They can select their own username and password in this form. However, there can be no duplicate usernames in order to guard against more than one user having the same username and password.

When the form is submitted, a query is kicked off that checks to see if the username has already been chosen by another user. If not EOF, then the username is in use by someone else. If EOF, then the username is available. The problem exists when the user wants to update or change their username.

The problem is that, for some reason, if the user wants to update or change their username, nothing happens. Even worse, it's not even throwing any error messages. When the submit button is clicked, it just returns to the main page with no update message and, when I pull up the users information, it did not update. If I update any field EXCEPT the username...it works. I will list my code...because I have been staring too long at it and can't figure out why it isn't working OR throwing any error messages. Any help would certainly be appreciated!

Code:
If Request.Form("editSurveyBtn") <> "" Then

	'get the search criterion from the form
	surveySrchTerm = Request.Form("ID_member")
	surveySrchTerm = CLng(surveySrchTerm)
	
	'Dim verifyUserName
	verifyUserName = Request.Form("username")
	verifyUserName = cStr(verifyUserName)
	
	'verify that username has not been chosen by another user
	Dim sqlUserName
	Dim objRSUserName
	Set objRSUserName = Server.CreateObject("ADODB.Recordset")
	
	sqlUserName = "SELECT member_survey.ID_member, member_survey.username FROM member_survey WHERE member_survey.username='" & verifyUserName & "';"
	
	'open a recordset containing the one record we want to edit
	objRSUserName.Open sqlUserName, objConn, 2, 3
	
	If Not objRSUserName.EOF Then
		If Not objRSUserName("memberID") = surveySrchTerm Then
		
		'if we are not EOF, then the username exists and cannot be used again.  Refresh form with error message

	Response.Redirect "[URL unfurl="true"]http://www.cbstest.com/admin/surveys.asp?display=survey&choice=edit&error=error&id="[/URL] & surveySrchTerm
		
	Else 

        (run update query)
End If
End If
 
can we see the update statement
also I noticed you are casting to a long on surveySrchTerm.
So are you certain these values are equal?
objRSUserName("memberID") = surveySrchTerm


General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
Yes. They are the same. I noticed that to, as I was using an Alias and changed it back. I will post the revised code. Thanks.

Code:
If Request.Form("editSurveyBtn") <> "" Then

	'get the search criterion from the form
	surveySrchTerm = Request.Form("ID_member")
	surveySrchTerm = CLng(surveySrchTerm)
	
	'Dim verifyUserName
	verifyUserName = Request.Form("username")
	verifyUserName = cStr(verifyUserName)
	
	'verify that username has not been chosen by another user
	'Dim sqlUserName
	'Dim objRSUserName
	Set objRSUserName = Server.CreateObject("ADODB.Recordset")
	
	sqlUserName = "SELECT member_survey.ID_member, member_survey.username FROM member_survey WHERE member_survey.username='" & verifyUserName & "';"
	
	'open a recordset containing the one record we want to edit
	objRSUserName.Open sqlUserName, objConn, 2, 3
	
	If Not objRSUserName.EOF Then
		If Not objRSUserName("ID_member") = surveySrchTerm Then
		
		'if we are not EOF, then the username exists and cannot be used again.
		'Response.Write "The username you have selected is not available.<br>Please select another username."
		Response.Redirect "[URL unfurl="true"]http://www.cbstest.com/admin/surveys.asp?display=survey&choice=edit&error=error&id="[/URL] & surveySrchTerm
		
	'End If
		
	Else 'If objRSUsername("ID_member") = userEditSrchTerm Then
	
	
	'create recordset object
	Dim sqlSurveyUpdate
	Dim objRSSurveyUpdate
	Set objRSSurveyUpdate = Server.CreateObject("ADODB.Recordset")

	'write a SQL statement to get the one entry we want to edit

	'sqlSurveyUpdate = "SELECT * FROM member_survey WHERE ID_member = " & surveySrchTerm
	sqlSurveyUpdate = "SELECT member_survey.ID_member, member_survey.current_date, member_survey.member_first, member_survey.member_last, member_survey.class, member_survey.job_title, member_survey.work_org, member_survey.work_address, member_survey.work_address2, member_survey.ID_work_city, member_survey.ID_work_state, member_survey.work_zip, member_survey.ID_work_pub, member_survey.work_phone, member_survey.work_fax, member_survey.ID_work_num_pub, member_survey.ID_work_fax_pub, member_survey.spouse, member_survey.home_address, member_survey.home_address2, member_survey.ID_home_city, member_survey.ID_home_state, member_survey.home_zip, member_survey.ID_home_pub, member_survey.home_phone, member_survey.ID_home_num_pub, member_survey.home_fax, member_survey.ID_home_fax_pub, member_survey.email, member_survey.ID_email_pub, member_survey.email2, member_survey.ID_email2_pub, member_survey.ID_employment_cat, member_survey.ID_employment, member_survey.volunteer1, member_survey.position1, member_survey.dates1, member_survey.volunteer2, member_survey.position2, member_survey.dates2, member_survey.volunteer3, member_survey.position3, member_survey.dates3, member_survey.volunteer4, member_survey.position4, member_survey.dates4, member_survey.volunteer5, member_survey.position5, member_survey.dates5, member_survey.agency1, member_survey.agency_pos1, member_survey.agency2, member_survey.agency_pos2, member_survey.agency3, member_survey.agency_pos3, member_survey.agency4, member_survey.agency_pos4, member_survey.agency5, member_survey.agency_pos5, member_survey.ID_volunteer_pub, member_survey.username, member_survey.password, member_survey.dues_paid_date, member_survey.dues_renewal_date, member_survey.ID_access, member_survey.ID_reviewed FROM member_survey WHERE (((member_survey.ID_member)=" & surveySrchTerm & "));"
	'sqlSurveyUpdate = "UPDATE nominees SET nominees.nominator_first = " & Request.Form("nominator_first") & ", nominees.nominator_last = " & Request.Form("nominator_last") & ", nominees.ID_year = " & Request.Form("ID_year") & ", nominees.ID_contact = " & Request.Form("ID_contact") & ", nominees.contact_info = " & Request.Form("contact_info") & ", nominees.nominee_first = " & Request.Form("nominee_first") & ", nominees.nominee_last = " & Request.Form("nominee_last") & ", nominees.employer = " & Request.Form("employer") & ", nominees.job_title = " & Request.Form("job_title") & ", nominees.address = " & Request.Form("address") & ", nominees.address2 = " & Request.Form("address2") & ", nominees.ID_city = " & Request.Form("ID_city") & ", nominees.ID_state = " & Request.Form("ID_state") & ", nominees.zip = " & Request.Form("zip") & ", nominees.phone = " & Request.Form("phone") & ", nominees.email = " & Request.Form("email") & ", nominees.roles = " & Request.Form("roles") & ", nominees.qualities = " & Request.Form("qualities") & ", nominees.curDate = " & Request.Form("curDate") & " WHERE (((nominees.ID_nominator) = " & surveySrchTerm & "));"
	
	'open a recordset containing the one record we want to edit
	objRSSurveyUpdate.Open sqlSurveyUpdate, objConn, 2, 3

	'move to the first (only) record

	objRSSurveyUpdate.MoveFirst

	'get the values from the form fields and assign them to the database fields for this record 
			objRSSurveyUpdate("member_first") = Request.Form("member_first")
			objRSSurveyUpdate("member_last") = Request.Form("member_last")
			objRSSurveyUpdate("class") = Request.Form("class")
			objRSSurveyUpdate("job_title") = Request.Form("job_title")
			objRSSurveyUpdate("work_org") = Request.Form("work_org")
			objRSSurveyUpdate("work_address") = Request.Form("work_address")
			objRSSurveyUpdate("work_address2") = Request.Form("work_address2")
			objRSSurveyUpdate("ID_work_city") = Request.Form("ID_work_city")
			objRSSurveyUpdate("ID_work_state") = Request.Form("ID_work_state")
			objRSSurveyUpdate("work_zip") = Request.Form("work_zip")
			objRSSurveyUpdate("ID_work_pub") = Request.Form("ID_work_pub")
			objRSSurveyUpdate("work_phone") = Request.Form("work_phone")
			objRSSurveyUpdate("work_fax") = Request.Form("work_fax")
			objRSSurveyUpdate("ID_work_num_pub") = Request.Form("ID_work_num_pub")
			objRSSurveyUpdate("ID_work_fax_pub") = Request.Form("ID_work_fax_pub")
			objRSSurveyUpdate("spouse") = Request.Form("spouse")
			objRSSurveyUpdate("home_address") = Request.Form("home_address")
			objRSSurveyUpdate("home_address2") = Request.Form("home_address2")
			objRSSurveyUpdate("ID_home_city") = Request.Form("ID_home_city")
			objRSSurveyUpdate("ID_home_state") = Request.Form("ID_home_state")
			objRSSurveyUpdate("home_zip") = Request.Form("home_zip")
			objRSSurveyUpdate("ID_home_pub") = Request.Form("ID_home_pub")
			objRSSurveyUpdate("ID_home_num_pub") = Request.Form("ID_home_num_pub")
			objRSSurveyUpdate("home_fax") = Request.Form("home_fax")
			objRSSurveyUpdate("ID_home_fax_pub") = Request.Form("ID_home_fax_pub")
			objRSSurveyUpdate("email") = Request.Form("email")
			objRSSurveyUpdate("ID_email_pub") = Request.Form("ID_email_pub")
			objRSSurveyUpdate("email2") = Request.Form("email2")
			objRSSurveyUpdate("ID_email2_pub") = Request.Form("ID_email2_pub")
			objRSSurveyUpdate("ID_employment_cat") = Request.Form("ID_employment_cat")
			objRSSurveyUpdate("ID_employment") = Request.Form("ID_employment")
			objRSSurveyUpdate("volunteer1") = Request.Form("volunteer1")
			objRSSurveyUpdate("position1") = Request.Form("position1")
			objRSSurveyUpdate("dates1") = Request.Form("dates1")
			objRSSurveyUpdate("volunteer2") = Request.Form("volunteer2")
			objRSSurveyUpdate("position2") = Request.Form("position2")
			objRSSurveyUpdate("dates2") = Request.Form("dates2")
			objRSSurveyUpdate("volunteer3") = Request.Form("volunteer3")
			objRSSurveyUpdate("position3") = Request.Form("position3")
			objRSSurveyUpdate("dates3") = Request.Form("dates3")
			objRSSurveyUpdate("volunteer4") = Request.Form("volunteer4")
			objRSSurveyUpdate("position4") = Request.Form("position4")
			objRSSurveyUpdate("dates4") = Request.Form("dates4")
			objRSSurveyUpdate("volunteer5") = Request.Form("volunteer5")
			objRSSurveyUpdate("position5") = Request.Form("position5")
			objRSSurveyUpdate("dates5") = Request.Form("dates5")
			objRSSurveyUpdate("agency1") = Request.Form("agency1")
			objRSSurveyUpdate("agency_pos1") = Request.Form("agency_pos1")
			objRSSurveyUpdate("agency2") = Request.Form("agency2")
			objRSSurveyUpdate("agency_pos2") = Request.Form("agency_pos2")
			objRSSurveyUpdate("agency3") = Request.Form("agency3")
			objRSSurveyUpdate("agency_pos3") = Request.Form("agency_pos3")
			objRSSurveyUpdate("agency4") = Request.Form("agency4")
			objRSSurveyUpdate("agency_pos4") = Request.Form("agency_pos4")
			objRSSurveyUpdate("agency5") = Request.Form("agency5")
			objRSSurveyUpdate("agency_pos5") = Request.Form("agency_pos5")
			objRSSurveyUpdate("ID_volunteer_pub") = Request.Form("ID_volunteer_pub")
			objRSSurveyUpdate("username") = Request.Form("username")
			objRSSurveyUpdate("password") = Request.Form("password")
			If objRSSurveyUpdate("dues_paid_date")<>"" Then	
				objRSSurveyUpdate("dues_paid_date") = Request.Form("dues_paid_date")
			'Else
			'	Response.Write "N/A"
			End If
			If objRSSurveyUpdate("dues_renewal_date")<>"" Then
				objRSSurveyUpdate("dues_renewal_date") = cDate(Request.Form("dues_renewal_date"))
			'Else
			'	Response.Write "N/A"
			End If
			
			'If date() >= cDate(Request.Form("dues_renewal_date")) Then
			'	objRSSurveyUpdate("dues_renewal_date") = dateAdd("d",365.24,cDate(Request.Form("dues_renewal_date")))
			'Else
			'	objRSSurveyUpdate("dues_renewal_date") = cDate(Request.Form("dues_renewal_date"))
			'End If
			
			objRSSurveyUpdate("ID_access") = Request.Form("ID_access")
			objRSSurveyUpdate("ID_reviewed") = Request.Form("ID_reviewed")

	' and here is current date
	'objRS("EditDate") = Date()
	
	'update the database now
	objRSSurveyUpdate.Update
 
Wow

alright. lets optimize for one. First thing sense you are doing a UPDATE I would recommend going with a straight .Execute always in Classic ASP.

So basically you would build the UPDATE statement as you are building the SELECT in the variable sqlSurveyUpdate.

I see you already started to do that above but have it commented out.

Build the UPDATE statement and then all you need to do is use the Execute method on the connection as follows

connectionObject.Execute(sqlSurveyUpdate)
'then you can test it
Response.Write sqlSurveyUpdate
Response.End

That way if the form colleciton is to blame for things not working you can act on it.

Next this is I would write a validation function and pass it parms so you can clean things up. You are testing normal things such as empty space and valid dates.

so say you want to test dues_paid_date for no val and also a valid date format. you would want a funciton such as
Code:
function validate(parm)
 ' check exists
 If parm = "" Then
   validate = 0
 elseIf NOT IsDate(parm) Then
   validate = 0 
 else
   validate = 1
 end if
end function

you can return anything you want also. If you're not worried about the date value per say you can return 1/1/1900 and data mine those out later. it's up to the business needs.

All you would need then is to do something like this in your UPDATE build

UPDATE nominees SET nominees.nominator_first = #" & validate(Request.Form("date")) ……

And it will clean things up and make ti much easier to debug if needed.

Of course these are suggestions on rewriting this process you have. I'll take a look closer and see if I can spot the bug on why the existing code may not be updating (if someone else doesn't see it)



General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
I noticed I read what you were validating a bit backwards there on the empty values. Is ti suppose to be that way? if the row has no value in that column do not update it?


General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
Yes. I agree on rewriting my code into a more simplified UPDATE statement and running it. It does make it that much cleaner. I put the commented out UPDATE statement as a guide for rewriting it.

I did change from cLng to cInt and made the following changes to my code and received this error. The ID_member is just an autonumber.

Code:
error '80020009' 
Exception occurred. 

/admin/includes/editsurveys.asp, line 1305

The changes to my code are as follows:
Code:
If Request.Form("editSurveyBtn") <> "" Then

	'get the search criterion from the form
	surveySrchTerm = Request.Form("ID_member")
	surveySrchTerm = CInt(surveySrchTerm)
	
	'Dim verifyUserName
	verifyUserName = Request.Form("username")
	verifyUserName = cStr(verifyUserName)
	
	'verify that username has not been chosen by another user
	'Dim sqlUserName
	'Dim objRSUserName
	Set objRSUserName = Server.CreateObject("ADODB.Recordset")
	
	sqlUserName = "SELECT member_survey.ID_member, member_survey.username FROM member_survey WHERE member_survey.username='" & verifyUserName & "';"
	
	'open a recordset containing the one record we want to edit
	objRSUserName.Open sqlUserName, objConn, 2, 3
[b][u]	
	If Not objRSUserName.EOF Then
		
		'if we are not EOF, then the username exists and cannot be used again.
		'Response.Write "The username you have selected is not available.<br>Please select another username."
		Response.Redirect "[URL unfurl="true"]http://www.cbstest.com/admin/surveys.asp?display=survey&choice=edit&error=error&id="[/URL] & surveySrchTerm
		
	'End If
		
	ElseIf Not objRSUserName("ID_member") = surveySrchTerm Then

		Response.Redirect "[URL unfurl="true"]http://www.cbstest.com/admin/surveys.asp?display=survey&choice=edit&error=error&id="[/URL] & surveySrchTerm
[/u][/b]
	Else
        (run update query)

Does this help shed any light? I've been staring way too long at this...so I could very well be missing something blatantly obvious.

Thanks for any help you can provide!

G
 
You didn't post the UPDATE portion. Let us know what line 1305 is also.

I was thinking alongs the lines of this
Code:
<%

If Request.Form("editSurveyBtn") <> "" Then
    surveySrchTerm = Request.Form("ID_member")
    surveySrchTerm = CInt(surveySrchTerm)
    verifyUserName = Request.Form("username")
    verifyUserName = cStr(verifyUserName)

    Set objRSUserName = Server.CreateObject("ADODB.Recordset")

    sqlUserName = "SELECT member_survey.ID_member, : & _
    			  "member_survey.username FROM member_survey " & _
    			  "WHERE member_survey.username='" & verifyUserName & "';"

    objRSUserName.Open sqlUserName, objConn, 2, 2

    If Not objRSUserName.EOF Then
        Response.Redirect "[URL unfurl="true"]http://www.cbstest.com/admin/surveys.asp?display=survey&choice=edit&error=error&id="[/URL] & surveySrchTerm
    ElseIf Not objRSUserName("ID_member") = surveySrchTerm Then
        Response.Redirect "[URL unfurl="true"]http://www.cbstest.com/admin/surveys.asp?display=survey&choice=edit&error=error&id="[/URL] & surveySrchTerm
    Else

Dim sqlSurveyUpdate

sqlSurveyUpdate = "UPDATE nominees SET " & _
			"  member_first = " & Request.Form("member_first") & _
		    " ,member_last = " & Request.Form("member_last") & _
		    " ,class = " & Request.Form("class") & _
		    " ,job_title = " & Request.Form("job_title") & _
		    " ,work_org = " & Request.Form("work_org") & _
		    " ,work_address = " & Request.Form("work_address") & _
		    " ,work_address2 = " & Request.Form("work_address2") & _
				.......... more fields ..........
		    " ,agency4 = " & Request.Form("agency4") & _
		    " ,agency_pos4 = " & Request.Form("agency_pos4") & _
		    " ,agency5 = " & Request.Form("agency5") & _
		    " ,agency_pos5 = " & Request.Form("agency_pos5") & _
		    " ,ID_volunteer_pub = " & Request.Form("ID_volunteer_pub") & _
		    " ,username = " & Request.Form("username") & _
		    " ,password = " & Request.Form("password") & _
		    " ,ID_access = " & Request.Form("ID_access") & _
		    " ,ID_reviewed = " & Validate(Request.Form("ID_reviewed"))  & _
		    " WHERE username='" & [i]unique identifier[/i] & "';"

'uncomment to test sql statement in analyzer
'Response.Write sqlSurveyUpdate
'Response.End

Conn.Execute(sqlSurveyUpdate)


Function Validate(parm)

	 ' check exists
	 If parm = "" Then
	   validate = 0
	 elseIf NOT IsDate(parm) Then
	   validate = 0
	 else
	   validate = 1
	 end if

End Function
%>

Although if indeed you need to validate empty values in the database ahead of performing this update then I would recomend a stored procedure all the way. however with the ";" being there I'm assuming this is an access database (ick :p) so the other option is if there is a relational value between the table nominees and the table member_survey then I would join them and use the value return to validate so you don't have to exhaust resources on the RS's.

I don't quite see the relation in the tables though. It is late of course ;)

On a side note. when I've been looking at a bit of code that I just cannot get right for too long I walk away for a bit. Even ten minutes can help bring out the solution.


General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
Line 1305 is this:
Code:
	ElseIf Not objRSUserName("ID_member") = surveySrchTerm Then

Yes, this is an Access database. Client does not have anything more powerful (like SQL Server).

There is no relational value between nominees and survey. I used an UPDATE statement in a similar form for nominees, so I pasted it in this form (commented out, of course) so I could rewrite my Survey query the same instead of the way it is written currently.

As for your side note...I just went to get a beer and strolled around the house for 15 minutes. I agree with you 100% there.

It is getting late and I can't thank you enough for your help and suggestions. I will look at this more tomorrow and try some of your suggestions out and let you know. Thanks again!

G
 
no problem and I hope I helped a bit.


General FAQ faq333-2924
5 steps to asking a question faq333-3811
 
OK...I've re-written my query from a SELECT to an UPDATE. Now I am getting a syntax error...which I think means I'm getting close.

Code:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14' 

[Microsoft][ODBC Microsoft Access Driver] Syntax error in UPDATE statement. 

/admin/includes/editsurveys.asp, line 1385

My new query is:

Code:
	Dim sqlSurveyUpdate

	'write a SQL statement to get the one entry we want to edit


	sqlSurveyUpdate = "UPDATE member_survey SET " & _
					  "current_date = " & Request.Form("current_date") & _
					  ", member_first = " & Request.Form("member_first") & _
					  ", member_last = " & Request.Form("member_last") & _
					  ", class = " & Request.Form("class") & _
					  ", job_title = " & Request.Form("job_title") & _
					  ", work_org = " & Request.Form("work_org") & _
					  ", work_address = " & Request.Form("work_address") & _
					  ", work_address2 = " & Request.Form("work_address2") & _
					  ", ID_work_city = " & Request.Form("ID_work_city") & _
					  ", ID_work_state = " & Request.Form("ID_work_state") & _
					  ", work_zip = " & Request.Form("work_zip") & _
					  ", ID_work_pub = " & Request.Form("ID_work_pub") & _
					  ", work_phone = " & Request.Form("work_phone") & _
					  ", work_fax = " & Request.Form("work_fax") & _
					  ", ID_work_num_pub = " & Request.Form("ID_work_num_pub") & _
					  ", ID_work_fax_pub = " & Request.Form("ID_work_fax_pub") & _
					  ", spouse = " & Request.Form("spouse") & _
					  ", home_address = " & Request.Form("home_address") & _
					  ", home_address2 = " & Request.Form("home_address2") & _
					  ", ID_home_city = " & Request.Form("ID_home_city") & _
					  ", ID_home_state = " & Request.Form("ID_home_state") & _
					  ", home_zip = " & Request.Form("home_zip") & _
					  ", ID_home_pub = " & Request.Form("ID_home_pub") & _
					  ", home_phone = " & Request.Form("home_phone") & _
					  ", ID_home_num_pub = " & Request.Form("ID_home_num_pub") & _
					  ", home_fax = " & Request.Form("home_fax") & _
					  ", ID_home_fax_pub = " & Request.Form("ID_home_fax_pub") & _
					  ", email = " & Request.Form("email") & _
					  ", ID_email_pub = " & Request.Form("ID_email_pub") & _
					  ", email2 = " & Request.Form("email2") & _
					  ", ID_email2_pub = " & Request.Form("ID_email2_pub") & _
					  ", ID_employment_cat = " & Request.Form("ID_employment_cat") & _
					  ", ID_employment = " & Request.Form("ID_employment") & _
					  ", volunteer1 = " & Request.Form("volunteer1") & _
					  ", position1 = " & Request.Form("position1") & _
					  ", dates1 = " & Request.Form("dates1") & _
					  ", volunteer2 = " & Request.Form("volunteer2") & _
					  ", position2 = " & Request.Form("position2") & _
					  ", dates2 = " & Request.Form("dates2") & _
					  ", volunteer3 = " & Request.Form("volunteer3") & _
					  ", position3 = " & Request.Form("position3") & _
					  ", dates3 = " & Request.Form("dates3") & _
					  ", volunteer4 = " & Request.Form("volunteer4") & _
					  ", position4 = " & Request.Form("position4") & _
					  ", dates4 = " & Request.Form("dates4") & _
					  ", volunteer5 = " & Request.Form("volunteer5") & _
					  ", position5 = " & Request.Form("position5") & _
					  ", dates5 = " & Request.Form("dates5") & _
					  ", agency1 = " & Request.Form("agency1") & _
					  ", agency_pos1 = " & Request.Form("agency_pos1") & _
					  ", agency2 = " & Request.Form("agency2") & _
					  ", agency_pos2 = " & Request.Form("agency_pos2") & _
					  ", agency3 = " & Request.Form("agency3") & _
					  ", agency_pos3 = " & Request.Form("agency_pos3") & _
					  ", agency4 = " & Request.Form("agency4") & _
					  ", agency_pos4 = " & Request.Form("agency_pos4") & _
					  ", agency5 = " & Request.Form("agency5") & _
					  ", agency_pos5 = " & Request.Form("agency_pos5") & _
					  ", ID_volunteer_pub = " & Request.Form("ID_volunteer_pub") & _
					  ", username = " & Request.Form("username") & _
					  ", password = " & Request.Form("password") & _
					  ", dues_paid_date = " & Request.Form("dues_paid_date") & _
					  ", dues_renewal_date = " & Request.Form("dues_renewal_date") & _
					  ", ID_access = " & Request.Form("ID_access") & _
					  ", ID_reviewed = " & Request.Form("ID_reviewed") & _ 
					  " WHERE ID_member=" & surveySrchTerm & ";"

						objConn.Execute(sqlSurveyUpdate)

Line 1385 is:
Code:
objConn.Execute(sqlSurveyUpdate)

I will search for the syntax error tomorrow...unless someone else can spot it first!

Thanks for everything, Onpnt!

G
 
All 'built-up' SQL statements are prone to syntax errors, as it's hard to see what the actually produce.
onpnt said:
Build the UPDATE statement and then all you need to do is use the Execute method on the connection as follows

connectionObject.Execute(sqlSurveyUpdate)
'then you can test it
Response.Write sqlSurveyUpdate
Response.End

That way if the form colleciton is to blame for things not working you can act on it.
For test purposes, rem out the .Execute line, so you can get to the Response.Write line. Try that, and post the results here if the syntax error isn't obvious. Also check that result for NULLs in non-NULL fields.

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
I think the syntax error may be centered around the three fields that are capturing dates. Seeing that this is using an Access database, I would need to be using the # signs, right? How would I write the in my UPDATE query?
 
Here are the results of my UPDATE query after commenting out the Execute line:

Code:
UPDATE member_survey SET current_date = 2/22/2006, member_first = Tom, member_last = Thumbs, class = 2019, job_title = slave, work_org = work, work_address = test, work_address2 = test, ID_work_city = 8, ID_work_state = 2, work_zip = 02000, ID_work_pub = 1, work_phone = test, work_fax = test, ID_work_num_pub = 1, ID_work_fax_pub = 1, spouse = test, home_address = test, home_address2 = test, ID_home_city = 5, ID_home_state = 2, home_zip = 02000, ID_home_pub = 1, home_phone = test, ID_home_num_pub = 1, home_fax = test, ID_home_fax_pub = 1, email = test, ID_email_pub = 1, email2 = test, ID_email2_pub = 2, ID_employment_cat = 12, ID_employment = 2, volunteer1 = test, position1 = test, dates1 = test, volunteer2 = test, position2 = test, dates2 = test, volunteer3 = test, position3 = test, dates3 = test, volunteer4 = test, position4 = test, dates4 = test, volunteer5 = test, position5 = test, dates5 = test, agency1 = test, agency_pos1 = test, agency2 = test, agency_pos2 = test, agency3 = test, agency_pos3 = test, agency4 = test, agency_pos4 = test, agency5 = , agency_pos5 = , ID_volunteer_pub = 1, username = tdumb, password = tt0222, dues_paid_date = 2/2/2006, dues_renewal_date = 6/30/2006, ID_access = 2, ID_reviewed = 2 WHERE ID_member=225;

There are several fields that can accept NULL values that were working before I added the username and password fields. I'm a little puzzled...but hope someone can spot the bug. I need to go get some more caffeine.

Thanks,
G
 
You will need single quotes around all the text strings. For example the member_first code should read:
Code:
", member_first = [COLOR=red]'[/color]" & Request.Form("member_first") & "[COLOR=red]'[/color],

________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first.
'If we're supposed to work in Hex, why have we only got A fingers?'
Drive a Steam Roller
 
OK. My UPDATE query works great now. THANKS MUCH!!! The help was most appreciated (and is something that I should have figured out on my own...but will never forget now!) :)

Now I have this problem and have not been able to fix it myself or find an answer on the internet.

If I pull up a user's info and try to edit their information, I can make any changes except to the username and everything works fine. IF I make a change to their username, the form submits, but nothing is updated.

Upon submit, I want to run a query to see if the username is in use by someone else. If EOF, then it is not in use and I can update. If not EOF, then I want to check and see if it is in use by the member I am trying to update. If it is in use by that member, update. If the username is being used by someone else, then don't update, repost the page and send an error message.

Here is my code:

Code:
If Request.Form("editSurveyBtn") <> "" Then

	'get the search criterion from the form
	surveySrchTerm = Request.Form("ID_member")
	surveySrchTerm = CInt(surveySrchTerm)
	'Response.Write surveySrchTerm
	
	verifyUserName = Request.Form("username")
	verifyUserName = cStr(verifyUserName)
		
	'verify that username has not been chosen by another user
	Set objRSUserName = Server.CreateObject("ADODB.Recordset")
	
	sqlUserName = "SELECT ID_member, " & _
				  "username FROM member_survey " & _
				  "WHERE member_survey.username='" & verifyUserName & "';"
	
	'open a recordset containing the one record we want to edit
	objRSUserName.Open sqlUserName, objConn, 2, 3
	
	If Not objRSUserName.EOF Then
		'Response.Redirect "[URL unfurl="true"]http://www.cbstest.com/admin/surveys.asp?display=survey&choice=edit&error=error&id="[/URL] & surveySrchTerm
		If Not objRSUserName("ID_member") = surveySrchTerm Then
			Response.Redirect "[URL unfurl="true"]http://www.cbstest.com/admin/surveys.asp?display=survey&choice=edit&error=error&id="[/URL] & surveySrchTerm
	Else
		
	'create recordset object
	Dim sqlSurveyUpdate
	'Dim objRSSurveyUpdate
	'Set objRSSurveyUpdate = Server.CreateObject("ADODB.Recordset")

	'write a SQL statement to get the one entry we want to edit

	sqlSurveyUpdate = "UPDATE member_survey SET " & _
					  "current_date = '" & Request.Form("current_date") & _
					  "', member_first = '" & Request.Form("member_first") & _
					  "', member_last = '" & Request.Form("member_last") & _
					  "', class = '" & Request.Form("class") & _
					  "', job_title = '" & Request.Form("job_title") & _
					  "', work_org = '" & Request.Form("work_org") & _
					  "', work_address = '" & Request.Form("work_address") & _
					  "', work_address2 = '" & Request.Form("work_address2") & _
					  "', ID_work_city = '" & Request.Form("ID_work_city") & _
					  "', ID_work_state = '" & Request.Form("ID_work_state") & _
					  "', work_zip = '" & Request.Form("work_zip") & _
					  "', ID_work_pub = '" & Request.Form("ID_work_pub") & _
					  "', work_phone = '" & Request.Form("work_phone") & _
					  "', work_fax = '" & Request.Form("work_fax") & _
					  (rest of update query)					  "', ID_volunteer_pub = '" & Request.Form("ID_volunteer_pub") & _
					  "', username = '" & Request.Form("username") & _
					  "', password = '" & Request.Form("password") & _
					  "', dues_paid_date = '" & Request.Form("dues_paid_date") & _
					  "', dues_renewal_date = '" & Request.Form("dues_renewal_date") & _
					  "', ID_access = '" & Request.Form("ID_access") & _
					  "', ID_reviewed = '" & Request.Form("ID_reviewed") & _ 
					  "' WHERE ID_member=" & surveySrchTerm & ";"

						objConn.Execute(sqlSurveyUpdate)

If I update anything but the username...everything works fine. If I update the username...my update query doesn't get run and nothing happens. Does anyone know why this works if I don't update the username?

Any help is always much appreciated!

Thanks,
G
 
Take a look at the part of the code:
[tt]
sqlUserName = "SELECT ID_member, " & _
"username FROM member_survey " & _
"[highlight]WHERE member_survey.username='" & verifyUserName & "';"[/highlight][/tt]

The problem here is that the existing username is used to find the row that you wish to update.

Consider using two form elements, one for the existing username and one for the new username. You could even make the existing element hidden.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top