473,400 Members | 2,163 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,400 software developers and data experts.

redirect if record already exists in database

I'm wanting to do a simple controlled voting page. I too our webserver off
anonymous and everyone who accesses the website is a domain authenticated
user. I've already done some control structure pages based on
Request.ServerVariables("AUTH_USER"), which works great. That's also how I
would do this page, in my basic thinking.

My idea is to have an access database with two tables. One table will have
the vote written to it and the other table will have the AUTH_USER written
to it when the employee casts their vote. I'm wondering how I would do a
test against that table to see if their name has already been written to the
table. So, if an employee votes already, when they go to vote again, their
user logon would be tested against all entries in the table and if it
exists, the vote would not be written and they would be redirected to
another page that politely tells them they've already voted.

I'm hoping there is an easy answer for this. :)

Thanks,
Jim
Jul 22 '05 #1
4 3835
On Wed, 5 Jan 2005 13:59:28 -0700, "Jim in Arizona"
<ti*******@hotmail.com> wrote:
I'm wanting to do a simple controlled voting page. I too our webserver off
anonymous and everyone who accesses the website is a domain authenticated
user. I've already done some control structure pages based on
Request.ServerVariables("AUTH_USER"), which works great. That's also how I
would do this page, in my basic thinking.

My idea is to have an access database with two tables. One table will have
the vote written to it and the other table will have the AUTH_USER written
to it when the employee casts their vote. I'm wondering how I would do a
test against that table to see if their name has already been written to the
table. So, if an employee votes already, when they go to vote again, their
user logon would be tested against all entries in the table and if it
exists, the vote would not be written and they would be redirected to
another page that politely tells them they've already voted.

I'm hoping there is an easy answer for this. :)


Do a SELECT from the authorization table WHERE the user column is
equal to AUTH_USER, then branch on whether it's null. Or just us an
IF EXISTS in your query if your database supports that and do the
entire thing in a single query. Books Online has examples if you use
SQL Server.

Jeff
Jul 22 '05 #2
I'm using an access 2K database.

I'm trying to do what you suggested but I'm running into some trouble. I'm
getting this error:

a.. Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'SELECT * from voting'
/castvote.asp, line 17

Here's my code:

------------------------- castvote.asp-----------------------------

Dim empname, Conn, SQL1

empname = Request.ServerVariables("AUTH_USER")

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
server.mappath("eoty.mdb")

SQL1 = "SELECT * from votingemp where(voter = '" & empname & "')"

Conn.Execute SQL1,,129

'Response.Write(SQL1)

Response.Write(SQL1.Fields("voter"))

-------------------------------- end asp -----------------------------

When I comment out the Response.Write(SQL1.Fields("voter")) and uncomment
the Response.Write(SQL1), I get this SQL Statement:

SELECT * from votingemp where(voter = 'DOMAIN\jim')

I tested that statement in access and it worked fine.

Line 17 is Response.Write(SQL1.Fields("voter"))
My plan, if this was working, was to place the result of the
Response.Write(SQL1.Fields("voter")) into a variable like so:

testvariable = Response.Write(SQL1.Fields("voter"))

Then do some branching off of that like so:

If testvariable = empname Then
Response.Write("You already voted")
Else
VoteDB Insert string Here
End If

Am I heading in the right direction?

Thanks,
Jim


"Jeff Cochran" <je*********@zina.com> wrote in message
news:41****************@msnews.microsoft.com...
On Wed, 5 Jan 2005 13:59:28 -0700, "Jim in Arizona"
<ti*******@hotmail.com> wrote:
I'm wanting to do a simple controlled voting page. I too our webserver off
anonymous and everyone who accesses the website is a domain authenticated
user. I've already done some control structure pages based on
Request.ServerVariables("AUTH_USER"), which works great. That's also how I
would do this page, in my basic thinking.

My idea is to have an access database with two tables. One table will have
the vote written to it and the other table will have the AUTH_USER written
to it when the employee casts their vote. I'm wondering how I would do a
test against that table to see if their name has already been written to
the
table. So, if an employee votes already, when they go to vote again, their
user logon would be tested against all entries in the table and if it
exists, the vote would not be written and they would be redirected to
another page that politely tells them they've already voted.

I'm hoping there is an easy answer for this. :)


Do a SELECT from the authorization table WHERE the user column is
equal to AUTH_USER, then branch on whether it's null. Or just us an
IF EXISTS in your query if your database supports that and do the
entire thing in a single query. Books Online has examples if you use
SQL Server.

Jeff

Jul 22 '05 #3
"Jim in Arizona" <ti*******@hotmail.com> wrote in message
news:OU**************@TK2MSFTNGP11.phx.gbl...
"Jeff Cochran" <je*********@zina.com> wrote in message
news:41****************@msnews.microsoft.com...
On Wed, 5 Jan 2005 13:59:28 -0700, "Jim in Arizona"
<ti*******@hotmail.com> wrote:
I'm wanting to do a simple controlled voting page. I too our webserver offanonymous and everyone who accesses the website is a domain authenticateduser. I've already done some control structure pages based on
Request.ServerVariables("AUTH_USER"), which works great. That's also how Iwould do this page, in my basic thinking.

My idea is to have an access database with two tables. One table will havethe vote written to it and the other table will have the AUTH_USER writtento it when the employee casts their vote. I'm wondering how I would do a
test against that table to see if their name has already been written to
the
table. So, if an employee votes already, when they go to vote again, theiruser logon would be tested against all entries in the table and if it
exists, the vote would not be written and they would be redirected to
another page that politely tells them they've already voted.

I'm hoping there is an easy answer for this. :)


Do a SELECT from the authorization table WHERE the user column is
equal to AUTH_USER, then branch on whether it's null. Or just us an
IF EXISTS in your query if your database supports that and do the
entire thing in a single query. Books Online has examples if you use
SQL Server.

Jeff


I'm using an access 2K database.

I'm trying to do what you suggested but I'm running into some trouble. I'm
getting this error:

a.. Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'SELECT * from voting'
/castvote.asp, line 17

Here's my code:

------------------------- castvote.asp-----------------------------

Dim empname, Conn, SQL1

empname = Request.ServerVariables("AUTH_USER")

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
server.mappath("eoty.mdb")

SQL1 = "SELECT * from votingemp where(voter = '" & empname & "')"

Conn.Execute SQL1,,129

'Response.Write(SQL1)

Response.Write(SQL1.Fields("voter"))

-------------------------------- end asp -----------------------------

When I comment out the Response.Write(SQL1.Fields("voter")) and uncomment
the Response.Write(SQL1), I get this SQL Statement:

SELECT * from votingemp where(voter = 'DOMAIN\jim')

I tested that statement in access and it worked fine.

Line 17 is Response.Write(SQL1.Fields("voter"))
My plan, if this was working, was to place the result of the
Response.Write(SQL1.Fields("voter")) into a variable like so:

testvariable = Response.Write(SQL1.Fields("voter"))

Then do some branching off of that like so:

If testvariable = empname Then
Response.Write("You already voted")
Else
VoteDB Insert string Here
End If

Am I heading in the right direction?

Thanks,
Jim


Here are some observations:
1. SQL1 is a string, not a recordset object. You need to declare a recordset
object and assign it to the return value of the Conn.Execute call.

2. Please consider explicitly listing the columns in your SQL statement
instead of using "SELECT *". Here's an article that explains the benefits:
http://aspfaq.com/show.asp?id=2096

3. The parenthesis are unnecessary in the WHERE clause of your SQL
statement.

4. The third parameter in the Conn.Execute call is incorrect in this
context. The third parameter of the Execute method is the options parameter
which is a bitmask of command type and execution option values. 129
indicates a command type of text (1) which is correct plus an execution
option of "no records" (128) which is incorrect. So the value of the option
parameter should simply be 1. This is all outlined in the Connection.Execute
method documentation:
http://www.msdn.microsoft.com/librar...cnnexecute.asp

5. When dynamically constructing SQL statements, you should take steps to
validate the input. This includes but is not limited to escaping
apostrophes. In the alternative, you may want to consider avoiding dynamic
sql entirely by using a parameterized query.

6. Before attempting to access the recordset object, you should verify that
data was returned by inspecting the Recordset.EOF property.

7. The Response.Write method is a statement, not a function so you don't
need to use parenthesis when making the call.

8. Please consider closing/deallocating objects after your done with them.
Here's an article that explains why:
http://aspfaq.com/show.asp?id=2435

9. The quoted text of this reply has been reordered to preserve the flow of
the thread. When posting replies please consider placing them below the
quoted text or inline.

Here's a revision of your code with a number of the above observations
applied:

<%
Dim empname, Conn, rs, SQL1

empname = Request.ServerVariables("AUTH_USER")

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
server.mappath("eoty.mdb")

SQL1 = "SELECT voter from votingemp where voter = '" &
Replace(empname,"'","''") & "'"
Set rs = Conn.Execute(SQL1,,1)

'Response.Write(SQL1)
If rs.EOF Then
Response.Write "Record not found"
Else
Response.Write rs.Fields("voter")
End If

rs.Close : Set rs = Nothing
Conn.Close : Set Conn=Nothing
%>

HTH
-Chris Hohmann

Jul 22 '05 #4

"Chris Hohmann" <no****@thankyou.com> wrote in message
news:ek**************@TK2MSFTNGP11.phx.gbl...
"Jim in Arizona" <ti*******@hotmail.com> wrote in message
news:OU**************@TK2MSFTNGP11.phx.gbl...
"Jeff Cochran" <je*********@zina.com> wrote in message
news:41****************@msnews.microsoft.com...
> On Wed, 5 Jan 2005 13:59:28 -0700, "Jim in Arizona"
> <ti*******@hotmail.com> wrote:
>
>>I'm wanting to do a simple controlled voting page. I too our webserver off >>anonymous and everyone who accesses the website is a domain authenticated >>user. I've already done some control structure pages based on
>>Request.ServerVariables("AUTH_USER"), which works great. That's also
>>how I >>would do this page, in my basic thinking.
>>
>>My idea is to have an access database with two tables. One table will have >>the vote written to it and the other table will have the AUTH_USER written >>to it when the employee casts their vote. I'm wondering how I would do
>>a
>>test against that table to see if their name has already been written
>>to
>>the
>>table. So, if an employee votes already, when they go to vote again, their >>user logon would be tested against all entries in the table and if it
>>exists, the vote would not be written and they would be redirected to
>>another page that politely tells them they've already voted.
>>
>>I'm hoping there is an easy answer for this. :)
>
> Do a SELECT from the authorization table WHERE the user column is
> equal to AUTH_USER, then branch on whether it's null. Or just us an
> IF EXISTS in your query if your database supports that and do the
> entire thing in a single query. Books Online has examples if you use
> SQL Server.
>
> Jeff


I'm using an access 2K database.

I'm trying to do what you suggested but I'm running into some trouble.
I'm
getting this error:

a.. Error Type:
Microsoft VBScript runtime (0x800A01A8)
Object required: 'SELECT * from voting'
/castvote.asp, line 17

Here's my code:

------------------------- castvote.asp-----------------------------

Dim empname, Conn, SQL1

empname = Request.ServerVariables("AUTH_USER")

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
server.mappath("eoty.mdb")

SQL1 = "SELECT * from votingemp where(voter = '" & empname & "')"

Conn.Execute SQL1,,129

'Response.Write(SQL1)

Response.Write(SQL1.Fields("voter"))

-------------------------------- end asp -----------------------------

When I comment out the Response.Write(SQL1.Fields("voter")) and uncomment
the Response.Write(SQL1), I get this SQL Statement:

SELECT * from votingemp where(voter = 'DOMAIN\jim')

I tested that statement in access and it worked fine.

Line 17 is Response.Write(SQL1.Fields("voter"))
My plan, if this was working, was to place the result of the
Response.Write(SQL1.Fields("voter")) into a variable like so:

testvariable = Response.Write(SQL1.Fields("voter"))

Then do some branching off of that like so:

If testvariable = empname Then
Response.Write("You already voted")
Else
VoteDB Insert string Here
End If

Am I heading in the right direction?

Thanks,
Jim


Here are some observations:
1. SQL1 is a string, not a recordset object. You need to declare a
recordset
object and assign it to the return value of the Conn.Execute call.

2. Please consider explicitly listing the columns in your SQL statement
instead of using "SELECT *". Here's an article that explains the benefits:
http://aspfaq.com/show.asp?id=2096

3. The parenthesis are unnecessary in the WHERE clause of your SQL
statement.

4. The third parameter in the Conn.Execute call is incorrect in this
context. The third parameter of the Execute method is the options
parameter
which is a bitmask of command type and execution option values. 129
indicates a command type of text (1) which is correct plus an execution
option of "no records" (128) which is incorrect. So the value of the
option
parameter should simply be 1. This is all outlined in the
Connection.Execute
method documentation:
http://www.msdn.microsoft.com/librar...cnnexecute.asp

5. When dynamically constructing SQL statements, you should take steps to
validate the input. This includes but is not limited to escaping
apostrophes. In the alternative, you may want to consider avoiding dynamic
sql entirely by using a parameterized query.

6. Before attempting to access the recordset object, you should verify
that
data was returned by inspecting the Recordset.EOF property.

7. The Response.Write method is a statement, not a function so you don't
need to use parenthesis when making the call.

8. Please consider closing/deallocating objects after your done with them.
Here's an article that explains why:
http://aspfaq.com/show.asp?id=2435

9. The quoted text of this reply has been reordered to preserve the flow
of
the thread. When posting replies please consider placing them below the
quoted text or inline.

Here's a revision of your code with a number of the above observations
applied:

<%
Dim empname, Conn, rs, SQL1

empname = Request.ServerVariables("AUTH_USER")

Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
server.mappath("eoty.mdb")

SQL1 = "SELECT voter from votingemp where voter = '" &
Replace(empname,"'","''") & "'"
Set rs = Conn.Execute(SQL1,,1)

'Response.Write(SQL1)
If rs.EOF Then
Response.Write "Record not found"
Else
Response.Write rs.Fields("voter")
End If

rs.Close : Set rs = Nothing
Conn.Close : Set Conn=Nothing
%>

HTH
-Chris Hohmann

Thanks Chris. That put me in the right direction. I think I can get
accomplished what I've set out to do.

It seems that I'm still trying to get it strait in my head on when and when
not to use parenthesis. I'll get it strait someday.

Thanks for your guidance. I'll put it to good use.

Jim
Jul 22 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Ilan Sebba | last post by:
When it comes to adding records in related tables, Access is really smart. But when I try to do the same using ADO, I am really stupid. Say I have two parent tables (eg Course, Student) and one...
3
by: Don Seckler | last post by:
I have a data entry form called Draw. This form is used to enter data in the table called Draw. The table has the following fields: WholesalerID, MagID, IssueID, CopiesDist, and the index is...
5
by: BerkshireGuy | last post by:
Hello everyone, I have a bond form that a user uses to enter data. One of my fields, is PolicyNumber. I added some code on the Before Update event of txtPolicyNumber that checks to see if...
0
by: watto | last post by:
I have 2 tables joined by a query. The first table is a fixed list of types and contains 2 fields: Type which is a number and Description. This table lives in the front end db. The other table...
3
by: michael_vanommeren | last post by:
I have two web applications that I am working with and I am trying to do a Response.Redirect from one to the other. They are setup as separate web applications on the same IIS server. If I go...
5
by: accessman2 | last post by:
Hi, I have a question. I made the create the new user form. <script language="javascript"> function submitFrm() {
5
by: bill | last post by:
relative PHP newbie, not new to computing or web design Login page -get data page (bringing user name and password in form variables). get data page -display data page (bringing user name and...
6
by: Helena666 | last post by:
Hi Its been a while since I have built a database using access and vba and am a bit rusty. I am using a command button on a form to write a record to a table, using an append query. However I need...
1
by: gnawz | last post by:
Hi guys, I have a couple of php files that perform various tasks. I will use fields in my system and provide code as well I need help as follows: My database contains the fields Category...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.