Go Back   CodingForums.com > :: Server side development > ASP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 11-04-2012, 09:00 PM   PM User | #1
dalezjc
New Coder

 
Join Date: Jun 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
dalezjc is an unknown quantity at this point
Passing Checkbox Values

I have a form that I use to put servers in what we call maintenance mode. It's just a (dynamic) list of servers that the user will toggle a checkbox to put the respective server in maintenance mode. I'm using the objid (serverid) as the checkbox value, checking for null, and if not, then set the maintenance mode. However, I'm not passing anything at all. Below is my form and ASP code:

Form Code:
Code:
<form action="updatemm_select.asp" method="get">
<table >
        <td><input name="toggle_maint" type="checkbox" value="<% = objid %>">
        </td>
    </tr>
        <%rsqdb.MoveNext%>
        <%loop%>
<tr>
  <td align=center colspan=6>
  <input type="submit" value="Toggle Maint Mode" name="Maint">
  </td>
</tr>
</table>

ASP Code (updatemm_select.asp)
Code:
<%
Dim serverid, conn, rsUpdate, machineid, status, rsqdbmmon, rsqdbmmoff, strquery, rs, toggle_maint, command, maint

Function ChkString(string)
If string = "" Then string = " "
ChkString = Replace(string, "'", "'")
End Function

serverid = ChkString(Request.QueryString("serverid"))
machineid = ChkString(Request.QueryString("machineid"))
toggle_maint = ChkString(Request.QueryString("toggle_maint"))
maint = ChkString(Request.Form("maint"))


set Conn=Server.CreateObject("ADODB.Connection")
set rs = server.CreateObject("ADODB.Recordset")
Conn.open "Provider=sqloledb;Server=server;Initial Catalog=db;UID=user;PWD=pw;"

strQuery = "select name, status, objid from object where (objid like '" & Request.QueryString("objid") & "%') "

Set RS = conn.Execute( strQuery)

if request.querystring("objid") <> "" then
response.write ("ObjID: " )
response.write rs("objid")
end if
dalezjc is offline   Reply With Quote
Old 11-05-2012, 07:47 PM   PM User | #2
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Ummmm...
Code:
Function ChkString(string) 
    If string = "" Then string = " " 
    ChkString = Replace(string, "'", "'") 
End Function
The line in red is totally bogus. Kill it before it multiplies. The *LAST* thing you want to do is convert "" to a space!

As for the rest...

Code:
strQuery = "select name, status, objid from object where (objid like '" & Request.QueryString("objid") & "%') "
Where, pray tell, in your <form> to you see a field named objid???

The only field you show is this one:
Code:
<input name="toggle_maint" type="checkbox" value="<% = objid %>">
Secondly, given that toggle_maint contains exactly and precisely the value objid why would you then use LIKE in your query?

Thirdly, if the objid field in the DB is a NUMBER, then you should never put apostrophes around the value in the query.

Fourthly, what do you do if the user checks 2 or 3 or 4 of those checkboxes?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-06-2012, 02:19 PM   PM User | #3
dalezjc
New Coder

 
Join Date: Jun 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
dalezjc is an unknown quantity at this point
Thanks for your input Old Pedant. Let me start over. Here's the form data I'm trying to capture. I have a list of servers that I want to either put into or take out of maintenance mode, based on their checkbox selection. (See image)

I'm not sure how to capture the serverid when the form is submitted. I thought I could use the serverid as the value object but no luck.
Attached Thumbnails
Click image for larger version

Name:	Capture.JPG
Views:	56
Size:	19.3 KB
ID:	11688  
dalezjc is offline   Reply With Quote
Old 11-06-2012, 07:30 PM   PM User | #4
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
I would rather have seen the HTML instead of the screen shot.

You do that by bringing up the page in your browser, clicking on the VIEW menu of the browser, then the SOURCE or PAGE SOURCE menu item. That shows you the HTML as the browser sees it. Copy/paste the relevant code from that.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-07-2012, 12:34 AM   PM User | #5
dalezjc
New Coder

 
Join Date: Jun 2006
Posts: 17
Thanks: 0
Thanked 0 Times in 0 Posts
dalezjc is an unknown quantity at this point
That screenshot was a mockup because I was posting from home and didn't have access to my code. Here's my code:

Code:
<form action="updatemm_select.asp" method="get">
<table >
        <td><input name="toggle_maint" type="checkbox" value="<% = objid %>">
        </td>
    </tr>
        <%rsqdb.MoveNext%>
        <%loop%>
<tr>
  <td align=center colspan=6>
  <input type="submit" value="Toggle Maint Mode" name="Maint">
  </td>
</tr>
</table>
dalezjc is offline   Reply With Quote
Old 11-07-2012, 12:55 AM   PM User | #6
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Please go read what I wrote, again.

First of all, I *KNOW* that is *NOT* really your code.

You don't have the beginning of the loop shown, you don't show where objid comes from (probably from objid = rsqdb("some field name" but you don't show that).

And the HTML isn't even legal HTML. (A missing <tr> if nothing else.)

But that isn't why I wanted to see the HTML AND NOT THE ASP code. I wanted to see the KINDS of values that will be *IN* those checkbox values. Yes, it's important.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.

Last edited by Old Pedant; 11-07-2012 at 01:04 AM..
Old Pedant is offline   Reply With Quote
Old 11-07-2012, 12:56 AM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Oh, and you never mentioned: Is there any reason a user couldn't check ANY NUMBER of the checkboxes before submitting the <form>?
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Old 11-07-2012, 01:03 AM   PM User | #8
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,556
Thanks: 62
Thanked 4,055 Times in 4,024 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
Also, is there some reason you are using method="get" in your <form> tag instead of method="post"?

And is this page private to your company? That is, is the page accessible on the internet or is it strictly an inTRAnet page? If it is on the inTERnet, is it password protected?

FWIW, *IF* all my suspicions are correct, I *THINK* you will be able to simply do this on your updatemm_select.asp page to make it change *ALL* of the checked items to maintenance mode:
Code:
<%
set Conn=Server.CreateObject("ADODB.Connection")
Conn.open "Provider=sqloledb;Server=server;Initial Catalog=db;UID=user;PWD=pw;" 

sql = "UPDATE object SET status = 'maintenance' WHERE objid IN (" & Request("toggle_maint") & ")"
howmany = 0
conn.Execute sql, howmany

Response.Write "Changed " & howmany & " to maintenance mode"
conn.Close
%>
(The actual value you set status to of course depends on your needs, but that's the general idea.)

If you want, you can just try that code to see if it works.

But if it doesn't work, then I need all that I have asked for from you.
__________________
An optimist sees the glass as half full.
A pessimist sees the glass as half empty.
A realist drinks it no matter how much there is.
Old Pedant is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:09 AM.


Advertisement
Log in to turn off these ads.