By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,663 Members | 1,844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,663 IT Pros & Developers. It's quick & easy.

simple command button question

P: n/a
Hi,
I am trying to create a simple asp page that has one command button that
updates a database. The URL of the page is like this:

http://MyServer.com/Update.asp?UserName=Tom

My asp code is like this:

%@ Language=VBScript %>
<!--#include file="includes/openconnection.asp"-->

StringUserName = Request.QueryString("UserName")

StringSQL = UPDATE Users SET Current = 0 WHERE UserName = '" &
StringUserName & "'")

I need to build the command button so that it shows up on my page and then
execute StringSQL when the user clicks the button. How do I do this?

Thanks,
Sam

Jul 19 '05 #1
Share this Question
Share on Google+
13 Replies


P: n/a
Tim
look at html FORMs
post to another asp page to do the work.

when you can get the form in html working and posting, only then write the
asp page to capture what was posted (response.form or response.querystring)
and then with asp hit the database

sorry to be a bit vague - but it's a but of a vague question
Tim
"Samantha Smit" <sa******@spamaway.cybermesa.com> wrote in message
news:bl**********@reader2.nmix.net...
Hi,
I am trying to create a simple asp page that has one command button that
updates a database. The URL of the page is like this:

http://MyServer.com/Update.asp?UserName=Tom

My asp code is like this:

%@ Language=VBScript %>
<!--#include file="includes/openconnection.asp"-->

StringUserName = Request.QueryString("UserName")

StringSQL = UPDATE Users SET Current = 0 WHERE UserName = '" &
StringUserName & "'")

I need to build the command button so that it shows up on my page and then
execute StringSQL when the user clicks the button. How do I do this?

Thanks,
Sam

Jul 19 '05 #2

P: n/a
You realize of course that you will be setting all of your "Current" fields
to 0 if the UserName is Tom, right?

Page1.asp
<form method=get action=Page2.asp>
<input type=submit name="UserName" value="Tom">
</form>
<a href="Page2.asp?UserName=Tom">Click Here</a>

Page2.asp is the code you submitted, plus the line

connectionObject.Execute stringSQL

"Samantha Smit" <sa******@spamaway.cybermesa.com> wrote in message
news:bl**********@reader2.nmix.net...
Hi,
I am trying to create a simple asp page that has one command button that
updates a database. The URL of the page is like this:

http://MyServer.com/Update.asp?UserName=Tom

My asp code is like this:

%@ Language=VBScript %>
<!--#include file="includes/openconnection.asp"-->

StringUserName = Request.QueryString("UserName")

StringSQL = UPDATE Users SET Current = 0 WHERE UserName = '" &
StringUserName & "'")

I need to build the command button so that it shows up on my page and then
execute StringSQL when the user clicks the button. How do I do this?

Thanks,
Sam

Jul 19 '05 #3

P: n/a

"Tom B" <sh*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
You realize of course that you will be setting all of your "Current" fields to 0 if the UserName is Tom, right?


Wouldn't that be the goal?

Ray at work
Jul 19 '05 #4

P: n/a
CJ

"Tom B" <sh*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
You realize of course that you will be setting all of your "Current" fields to 0 if the UserName is Tom, right?
Yes, my real data is unique, I just thought I'd simplify the example.

I'm confused why I need 2 pages, sorry I'm new at this. Maybe additional
details would help. I want to include a URL in an email message that would
allow the recipient to change their "Current" field so they don't receive
emails in the future, sort of an unsubscribe process. The URL link in the
email will be like http://MyServer.com/Update.asp?UserName=Tom The user will
click on the link, load the asp page, and then click on the command button
which would update their record. I'm trying the method with two pages but
can't get anything to work. I'll keep trying. Any help is appreciated.

thanks,
Sam Page1.asp
<form method=get action=Page2.asp>
<input type=submit name="UserName" value="Tom">
</form>
<a href="Page2.asp?UserName=Tom">Click Here</a>

Page2.asp is the code you submitted, plus the line

connectionObject.Execute stringSQL

"Samantha Smit" <sa******@spamaway.cybermesa.com> wrote in message
news:bl**********@reader2.nmix.net...
Hi,
I am trying to create a simple asp page that has one command button that
updates a database. The URL of the page is like this:

http://MyServer.com/Update.asp?UserName=Tom

My asp code is like this:

%@ Language=VBScript %>
<!--#include file="includes/openconnection.asp"-->

StringUserName = Request.QueryString("UserName")

StringSQL = UPDATE Users SET Current = 0 WHERE UserName = '" &
StringUserName & "'")

I need to build the command button so that it shows up on my page and then execute StringSQL when the user clicks the button. How do I do this?

Thanks,
Sam


Jul 19 '05 #5

P: n/a
I assume so, but I thought I'd mention it.
Personally, I wouldn't use a string value as a Unique ID.
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:Oo*************@tk2msftngp13.phx.gbl...

"Tom B" <sh*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
You realize of course that you will be setting all of your "Current"

fields
to 0 if the UserName is Tom, right?


Wouldn't that be the goal?

Ray at work

Jul 19 '05 #6

P: n/a
Hi Chris/CJ/Sam,

You don't need to do it in two pages. It makes things easier for learning
though. I personally often use three pages for such things, actually. My
three pages would be like this:

page1.asp:

<form method="POST" action="page2.asp"> <!--note the method is post, not
get-->
Current username: <input type="text" name="txtCurrentUsername" /><br />
New username: <input type="text" name="txtNewUsername" /><br />
<input type="submit" />
</form>

page2.asp:

<%
Dim sCurrentUsername, sNewUsername
Dim sSQL, oADO

sCurrentUsername = Request.Form("txtCurrentUsername")
sNewUsername = Request.Form("txtNewUsername")
sSQL = "UPDATE TheTable SET TheUsername='" & sNewUsername & "' WHERE
TheUsername='" & sCurrentUsername & "'"
Set oADO = Server.CreateObject("ADODB.Connection")
oADO.Open MyConnectionString
oADO.Execute sSQL
oADO.Close : Set oADO = Nothing
Response.Redirect "page3.asp"
%>

page3.asp:

<body>Thank you</body>

Does that make sense? It's just a basic example of things.

Ray at work
"CJ" <ch***@hrn.org> wrote in message news:bl**********@reader2.nmix.net...

Yes, my real data is unique, I just thought I'd simplify the example.

I'm confused why I need 2 pages, sorry I'm new at this. Maybe additional
details would help. I want to include a URL in an email message that would
allow the recipient to change their "Current" field so they don't receive
emails in the future, sort of an unsubscribe process. The URL link in the
email will be like http://MyServer.com/Update.asp?UserName=Tom The user will click on the link, load the asp page, and then click on the command button which would update their record. I'm trying the method with two pages but
can't get anything to work. I'll keep trying. Any help is appreciated.

thanks,
Sam

Jul 19 '05 #7

P: n/a
You, I, and a handful of other people are the only ones in the world who
think that way then. I get so homicidal when I think about all the software
that I have to deal with where I work that uses usernames as the unique ID.
This is how things flow where I work:

1. Ray, we bought this software. It uses SQL Server. Support it.
2. Okay, I have the server setup and the database created to their specs.
Give me a contact name of someone there. I have a question.
3. Person at software company, I have a question. It appears that you use a
person's username as the unique ID. Why? What happens when one of our
users gets married and she wants to change her username to conform to her
new name.
4. You can't change the username. It's tied to too many other things.
5. I want to kill people at your company. Bye.

Yeah, sure, if I wanted to, I could change the username and update all the
references to it elsewhere, but if I start modifying the database directly
myself, I violate support contracts.

That would be enough of my whining for now though. :]

Ray at work

"Tom B" <sh*****@hotmail.com> wrote in message
news:OD****************@TK2MSFTNGP10.phx.gbl...
I assume so, but I thought I'd mention it.
Personally, I wouldn't use a string value as a Unique ID.
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:Oo*************@tk2msftngp13.phx.gbl...

"Tom B" <sh*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
You realize of course that you will be setting all of your "Current"

fields
to 0 if the UserName is Tom, right?


Wouldn't that be the goal?

Ray at work


Jul 19 '05 #8

P: n/a
You don't need two pages.
Your link idea would work fine.

Update.asp
<%
Dim sUser
sUser=Request.QueryString("UserName")
if Request.QueryString("Postback")="true" then
'Open connection to database
Dim sSQL
sSQL="UPDATE Users Set Current=0 WHERE UserName='" & sUser& "'"
connectionObject.Execute sSQL
Response.Write "Database Updated"
end if
%>

<input type=hidden name=Postback Value="true">
<Form method=Get action=Update.asp>

<input type=hidden name=UserName Value="<%=sUser%>">
<input type=Submit name="Go">
</Form>

"CJ" <ch***@hrn.org> wrote in message news:bl**********@reader2.nmix.net...

"Tom B" <sh*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
You realize of course that you will be setting all of your "Current" fields
to 0 if the UserName is Tom, right?


Yes, my real data is unique, I just thought I'd simplify the example.

I'm confused why I need 2 pages, sorry I'm new at this. Maybe additional
details would help. I want to include a URL in an email message that would
allow the recipient to change their "Current" field so they don't receive
emails in the future, sort of an unsubscribe process. The URL link in the
email will be like http://MyServer.com/Update.asp?UserName=Tom The user

will click on the link, load the asp page, and then click on the command button which would update their record. I'm trying the method with two pages but
can't get anything to work. I'll keep trying. Any help is appreciated.

thanks,
Sam
Page1.asp
<form method=get action=Page2.asp>
<input type=submit name="UserName" value="Tom">
</form>
<a href="Page2.asp?UserName=Tom">Click Here</a>

Page2.asp is the code you submitted, plus the line

connectionObject.Execute stringSQL

"Samantha Smit" <sa******@spamaway.cybermesa.com> wrote in message
news:bl**********@reader2.nmix.net...
Hi,
I am trying to create a simple asp page that has one command button that updates a database. The URL of the page is like this:

http://MyServer.com/Update.asp?UserName=Tom

My asp code is like this:

%@ Language=VBScript %>
<!--#include file="includes/openconnection.asp"-->

StringUserName = Request.QueryString("UserName")

StringSQL = UPDATE Users SET Current = 0 WHERE UserName = '" &
StringUserName & "'")

I need to build the command button so that it shows up on my page and then execute StringSQL when the user clicks the button. How do I do this?

Thanks,
Sam



Jul 19 '05 #9

P: n/a
I'll admit I got burned the first time I wrote something that was used in
production. I didn't use the names as a UniqueID, but I didn't record the
"current name" as part of a transaction either. So when a person got
married, or changed their name for other reasons, I was able to change the
name, but it was reflected on the old data as well. Which of course, wasn't
right either.

My main motivation for using int's for UniqueIDs is purely because of my
belief that computers can handle them faster. I believe one of the normal
forms also suggests that the UniqueID should be irrelevant to the data (I
don't think that's the right way to put it) meaning that if it's related to
the data, it shouldn't be used. Thus, a name, SIN(SSI) etc. are not good
candidates.

"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:Ow**************@TK2MSFTNGP11.phx.gbl...
You, I, and a handful of other people are the only ones in the world who
think that way then. I get so homicidal when I think about all the software that I have to deal with where I work that uses usernames as the unique ID. This is how things flow where I work:

1. Ray, we bought this software. It uses SQL Server. Support it.
2. Okay, I have the server setup and the database created to their specs.
Give me a contact name of someone there. I have a question.
3. Person at software company, I have a question. It appears that you use a person's username as the unique ID. Why? What happens when one of our
users gets married and she wants to change her username to conform to her
new name.
4. You can't change the username. It's tied to too many other things.
5. I want to kill people at your company. Bye.

Yeah, sure, if I wanted to, I could change the username and update all the
references to it elsewhere, but if I start modifying the database directly
myself, I violate support contracts.

That would be enough of my whining for now though. :]

Ray at work

"Tom B" <sh*****@hotmail.com> wrote in message
news:OD****************@TK2MSFTNGP10.phx.gbl...
I assume so, but I thought I'd mention it.
Personally, I wouldn't use a string value as a Unique ID.
"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in message
news:Oo*************@tk2msftngp13.phx.gbl...

"Tom B" <sh*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
> You realize of course that you will be setting all of your "Current"
fields
> to 0 if the UserName is Tom, right?

Wouldn't that be the goal?

Ray at work



Jul 19 '05 #10

P: n/a
Thanks for responding Tom. My page currently looks like this:
<%
Dim sUser
sUser=Request.QueryString("UserName")
if Request.QueryString("Postback")="true" then
'Open connection to database
<!--#include file="includes/openconnection.asp"-->
Dim sSQL
sSQL="UPDATE Users Set Status=1 WHERE UserName='" & sUser& "'"
connectionObject.Execute sSQL
Response.Write "Database Updated"
end if
%>
<input type=hidden name=Postback Value="true">
<Form method=Get action=Update.asp>

<input type=hidden name=UserName Value="<%=sUser%>">
<input type=Submit name="Go">
</Form>

I load the URL http://MyServer.com/Update.asp?UserName=Tom. I see the button
called "Submit query". When I click it the URL changes to
http://MyServer.com/Update.asp?UserN...o=Submit+Query

I don't see the Database Updated message and my data is not updated. My
openconnection.asp file is working for a different page. The following
update SQL statement works in Query Analyzer, UPDATE Users Set Status =1
WHERE UserName = "Tom"

If I comment out "if Request.QueryString("Postback")="true" then.....End IF
I get
Microsoft VBScript runtime (0x800A01A8)
Object required: 'connectionObject'
/Test/Update.asp, line 13

Also where can I edit the label on the command button, I don't see the text
"Submit Query" anywhere. Is this some kind of default label.

Thanks for any help that you may be willing to provide.

Sam
"Tom B" <sh*****@hotmail.com> wrote in message
news:u1**************@TK2MSFTNGP12.phx.gbl...
You don't need two pages.
Your link idea would work fine.

Update.asp
<%
Dim sUser
sUser=Request.QueryString("UserName")
if Request.QueryString("Postback")="true" then
'Open connection to database
Dim sSQL
sSQL="UPDATE Users Set Current=0 WHERE UserName='" & sUser& "'"
connectionObject.Execute sSQL
Response.Write "Database Updated"
end if
%>

<input type=hidden name=Postback Value="true">
<Form method=Get action=Update.asp>

<input type=hidden name=UserName Value="<%=sUser%>">
<input type=Submit name="Go">
</Form>

"CJ" <ch***@hrn.org> wrote in message

news:bl**********@reader2.nmix.net...

"Tom B" <sh*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP10.phx.gbl...
You realize of course that you will be setting all of your "Current"

fields
to 0 if the UserName is Tom, right?


Yes, my real data is unique, I just thought I'd simplify the example.

I'm confused why I need 2 pages, sorry I'm new at this. Maybe additional
details would help. I want to include a URL in an email message that would
allow the recipient to change their "Current" field so they don't receive emails in the future, sort of an unsubscribe process. The URL link in the email will be like http://MyServer.com/Update.asp?UserName=Tom The user

will
click on the link, load the asp page, and then click on the command

button
which would update their record. I'm trying the method with two pages but can't get anything to work. I'll keep trying. Any help is appreciated.

thanks,
Sam
Page1.asp
<form method=get action=Page2.asp>
<input type=submit name="UserName" value="Tom">
</form>
<a href="Page2.asp?UserName=Tom">Click Here</a>

Page2.asp is the code you submitted, plus the line

connectionObject.Execute stringSQL

"Samantha Smit" <sa******@spamaway.cybermesa.com> wrote in message
news:bl**********@reader2.nmix.net...
> Hi,
> I am trying to create a simple asp page that has one command button that > updates a database. The URL of the page is like this:
>
> http://MyServer.com/Update.asp?UserName=Tom
>
> My asp code is like this:
>
> %@ Language=VBScript %>
> <!--#include file="includes/openconnection.asp"-->
>
> StringUserName = Request.QueryString("UserName")
>
> StringSQL = UPDATE Users SET Current = 0 WHERE UserName = '" &
> StringUserName & "'")
>
> I need to build the command button so that it shows up on my page

and then
> execute StringSQL when the user clicks the button. How do I do this?
>
> Thanks,
> Sam
>
>
>



Jul 19 '05 #11

P: n/a
I love it!

Mine is a little different.

1. Phil calls software company.
2. Software company says, reboot the server to fix it
3. Phil reboots server, asks what is wrong with software
3. Software won't admit that they really don't know. Then they ask
why I don't reboot the server once a week to keep the software running
4. Phil asks why they don't fix the software so I don't heave to
reboot once a week.
5. Phil is considered to be a "pain" :-)
--

Phillip Windell [CCNA, MVP, MCP]
pw******@wandtv.com
WAND-TV (ABC Affiliate)
www.wandtv.com

"Ray at <%=sLocation%>" <myfirstname at lane34 dot com> wrote in
message news:Ow**************@TK2MSFTNGP11.phx.gbl...
You, I, and a handful of other people are the only ones in the world who think that way then. I get so homicidal when I think about all the software that I have to deal with where I work that uses usernames as the unique ID. This is how things flow where I work:

1. Ray, we bought this software. It uses SQL Server. Support it.
2. Okay, I have the server setup and the database created to their specs. Give me a contact name of someone there. I have a question.
3. Person at software company, I have a question. It appears that you use a person's username as the unique ID. Why? What happens when one of our users gets married and she wants to change her username to conform to her new name.
4. You can't change the username. It's tied to too many other things. 5. I want to kill people at your company. Bye.

Jul 19 '05 #12

P: n/a
Nice!

See, this one of the reasons that no matter what the non-believers say about
Microsoft, they make good software. If they made software that required
such a routine, they'd fix it. And they know how to make their software
work together and not cause conflicts. If you setup an NT* machine and put
nothing but Microsoft software on it, it'll run forever flawlessly. Then
you go and install some junkware that you download off the Internet and
start getting Dr. Watsons all the time, and suddenly it's Microsoft's fault.
I can't stand that.

The above statements are meant to be generally true. I am aware that
nothing is 100%. :]

Ray at work

"Phillip Windell" <pwindell{at}wandtv*d0t*com> wrote in message
news:ON**************@TK2MSFTNGP10.phx.gbl...
I love it!

Mine is a little different.

1. Phil calls software company.
2. Software company says, reboot the server to fix it
3. Phil reboots server, asks what is wrong with software
3. Software won't admit that they really don't know. Then they ask
why I don't reboot the server once a week to keep the software running
4. Phil asks why they don't fix the software so I don't heave to
reboot once a week.
5. Phil is considered to be a "pain" :-)

Jul 19 '05 #13

P: n/a
"Tom B" <sh*****@hotmail.com> wrote in message
news:%2****************@TK2MSFTNGP12.phx.gbl...
I'll admit I got burned the first time I wrote something that was used in production. I didn't use the names as a UniqueID, but I didn't record the "current name" as part of a transaction either. So when a person got
married, or changed their name for other reasons, I was able to change the name, but it was reflected on the old data as well. Which of course, wasn't right either.

My main motivation for using int's for UniqueIDs is purely because of my belief that computers can handle them faster. I believe one of the normal forms also suggests that the UniqueID should be irrelevant to the data (I don't think that's the right way to put it) meaning that if it's related to the data, it shouldn't be used. Thus, a name, SIN(SSI) etc. are not good candidates.


I think the term is "non-meaningful" keys. I wish they would come up
with a term that doesn't carry such a negative connotation. How about
"keys that won't screw you down the line". Yes, that sums it up nicely.
:)

-Chris Hohmann
Jul 19 '05 #14

This discussion thread is closed

Replies have been disabled for this discussion.