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

Checkboxes not updating to db?

Status
Not open for further replies.

snowboardr

Programmer
Feb 22, 2002
1,401
PH
It doesnt seem to be updating my db using this: It doesn't give me an error it just doesn't update.

Code:
If Request.QueryString("mode") = "update" then
	set my_conn= Server.CreateObject("ADODB.Connection")
	set rs = Server.CreateObject("ADODB.RecordSet")

	my_conn.Open ConnString  '# I have ConnString = db.mdb etc in my code..

checkbox1 = rs("checkbox1")
	
If checkbox1 = "False" then
 	message = "Account status updated! test1"
 'sql update here
	SQL = "UPDATE users SET checkbox1 =" & "True WHERE user_id =" & "'" & rs("user_id") & "'"
	rs = my_conn.Execute (StrSQL)

	Else
	SQL = "UPDATE users SET checkbox1 =" & "False WHERE user_id =" & "'" & rs("user_id") & "'"
	rs = my_conn.Execute (StrSQL)

End if
End If

I don't need to update the checkboxes in this code because i have <% if checkbox1 = &quot;True&quot; then Response.write &quot;Checked&quot; %>


I am using Access 2002 I have tried &quot;True&quot; & &quot;False&quot; and -1 and 0 ... when I response.write the checkbox field it shows up as True, so that is what I have been trying to do to update it as well.

Any ideas?
 
Hi again

Following on from the thread you started before, Access does use -1 and 0 for a logical field in its ADO methods.

When your update is perfomed, are you checking that it is updating the database or are you looking at the results using another ASP page? You have to be careful with the latter because there is always the chance that an error is in the ASP page when displaying the logical field.

Does the users table have other fields in it? Try adding an update to another field in the SQL to see if the execute is working correctly.

If in doubt, and tearing your hair out still, change the logical field to a 1 character text field with a default value of &quot;n&quot; and then just update it to &quot;y&quot;. Does the same, looks the same, removes anxiety.
Derren
[The only person in the world to like Word]
 
I updated my code, still no luck I even switched over to Y & N because yes, checkboxes in the db where giving me anxiety attacks.



2 checkboxes

1 named &quot;approved&quot;
1 named &quot;locked&quot;


Code:
...above code (data) has already been retrieved and data has been dim'd

link_okay = rs(&quot;link_okay&quot;)
account_locked = rs(&quot;account_locked&quot;)

'#-----------end above code--------------

If Request.QueryString(&quot;mode&quot;) = &quot;update&quot; then
ConnString = &quot;Provider=Microsoft.Jet.OLEDB.4.0; Data Source=&quot; & Server.MapPath(&quot;../db.mdb&quot;)
	userid = Request.QueryString(&quot;user_id&quot;) 
	set my_conn= Server.CreateObject(&quot;ADODB.Connection&quot;)
	set rs = Server.CreateObject(&quot;ADODB.RecordSet&quot;)
   	
app = Request.Form(&quot;approved&quot;)
locked = Request.Form(&quot;locked&quot;)

my_conn.Open ConnString
If link_okay = &quot;Y&quot; then
	
	If NOT app = &quot;&quot; then
		
		SQL = &quot;UPDATE users SET link_okay=&quot; & &quot;'N'&quot; & &quot; WHERE user_id=&quot; & userid 
		rs = my_conn.Execute (SQL)
		End If
	
	Else

		If NOT app = &quot;&quot; then
		
		SQL = &quot;UPDATE users SET link_okay=&quot; & &quot;'Y'&quot; & &quot; WHERE user_id=&quot; & userid 
		rs = my_conn.Execute (SQL)
		End If
	
	
	End if


If account_locked = &quot;Y&quot; then
	
	If NOT locked = &quot;&quot; then
		
		SQL = &quot;UPDATE users SET account_locked=&quot; & &quot;'N'&quot; & &quot; WHERE user_id=&quot; & userid 
		rs = my_conn.Execute (SQL)
	End If
	

	Else

	If NOT locked = &quot;&quot; then
		
		SQL = &quot;UPDATE users SET account_locked=&quot; & &quot;'Y'&quot; & &quot; WHERE user_id=&quot; & userid
		rs = my_conn.Execute (SQL)
	End If
	
	
	End if

End if

%>

Hope this can be resolved...didn't know this would be that much of a headache.
 
Your logic is stating:

if link_ok is yes then

if app is NOT empty (then it must contain &quot;Y&quot;) update the database to say &quot;N&quot; (?)

otherwise,

if app is NOT empty (again - this will never get here because if app is not empty then it would be picked up by the first condition) update the value to &quot;Y&quot;

Should it not be

if app=&quot;&quot; then update the databse to &quot;N&quot;

Have a look Derren
[The only person in the world to like Word]
 
ahah yea I was just catching onto that, as I was rewriting this code for a 3rd time! Im just making it harder then it really is. =D Thanks alot for your help!

On a side note, do you know why I keep getting this?

When using INSERT & UPDATE
I get things from the db fine just not write..

Microsoft JET Database Engine error '80004005'
Operation must use an updateable query.
/test.asp, line 18

The only permissions I havn't been able to set is the ones found in [right-click folder > Properties > security tab] but I don't have the security tab on win Xp pro?? I have checked every other permissions route and no luck. The code works, I tested it on my host, so it has to be permissions of some sort.. It may be just time to switch back to good ole win2kpro
 
Sorry, I don't have any experience in that area - try posting another thread, I would be interested in the answer.

Good luck Derren
[The only person in the world to like Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top