473,651 Members | 2,485 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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.ServerV ariables("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 3849
On Wed, 5 Jan 2005 13:59:28 -0700, "Jim in Arizona"
<ti*******@hotm ail.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.Server Variables("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.ServerV ariables("AUTH_ USER")

Set Conn = Server.CreateOb ject("ADODB.Con nection")
Conn.Open "Provider=Micro soft.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("vo ter"))

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

When I comment out the Response.Write( SQL1.Fields("vo ter")) 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("vo ter"))
My plan, if this was working, was to place the result of the
Response.Write( SQL1.Fields("vo ter")) into a variable like so:

testvariable = Response.Write( SQL1.Fields("vo ter"))

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*********@zi na.com> wrote in message
news:41******** ********@msnews .microsoft.com. ..
On Wed, 5 Jan 2005 13:59:28 -0700, "Jim in Arizona"
<ti*******@hotm ail.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.Serve rVariables("AUT H_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*******@hotm ail.com> wrote in message
news:OU******** ******@TK2MSFTN GP11.phx.gbl...
"Jeff Cochran" <je*********@zi na.com> wrote in message
news:41******** ********@msnews .microsoft.com. ..
On Wed, 5 Jan 2005 13:59:28 -0700, "Jim in Arizona"
<ti*******@hotm ail.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.Serve rVariables("AUT H_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.ServerV ariables("AUTH_ USER")

Set Conn = Server.CreateOb ject("ADODB.Con nection")
Conn.Open "Provider=Micro soft.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("vo ter"))

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

When I comment out the Response.Write( SQL1.Fields("vo ter")) 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("vo ter"))
My plan, if this was working, was to place the result of the
Response.Write( SQL1.Fields("vo ter")) into a variable like so:

testvariable = Response.Write( SQL1.Fields("vo ter"))

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.Exec ute
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.ServerV ariables("AUTH_ USER")

Set Conn = Server.CreateOb ject("ADODB.Con nection")
Conn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" &
server.mappath( "eoty.mdb")

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

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

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

HTH
-Chris Hohmann

Jul 22 '05 #4

"Chris Hohmann" <no****@thankyo u.com> wrote in message
news:ek******** ******@TK2MSFTN GP11.phx.gbl...
"Jim in Arizona" <ti*******@hotm ail.com> wrote in message
news:OU******** ******@TK2MSFTN GP11.phx.gbl...
"Jeff Cochran" <je*********@zi na.com> wrote in message
news:41******** ********@msnews .microsoft.com. ..
> On Wed, 5 Jan 2005 13:59:28 -0700, "Jim in Arizona"
> <ti*******@hotm ail.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.Serve rVariables("AUT H_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.ServerV ariables("AUTH_ USER")

Set Conn = Server.CreateOb ject("ADODB.Con nection")
Conn.Open "Provider=Micro soft.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("vo ter"))

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

When I comment out the Response.Write( SQL1.Fields("vo ter")) 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("vo ter"))
My plan, if this was working, was to place the result of the
Response.Write( SQL1.Fields("vo ter")) into a variable like so:

testvariable = Response.Write( SQL1.Fields("vo ter"))

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.Exec ute
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.ServerV ariables("AUTH_ USER")

Set Conn = Server.CreateOb ject("ADODB.Con nection")
Conn.Open "Provider=Micro soft.Jet.OLEDB. 4.0;Data Source=" &
server.mappath( "eoty.mdb")

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

'Response.Write (SQL1)
If rs.EOF Then
Response.Write "Record not found"
Else
Response.Write rs.Fields("vote r")
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
4328
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 child table (StudentProgress). The course progress records how a student progresses on a course. I have one course (History) and one student called Maya. I now want to record her grade (64). If I do this in Access using a form, then the form...
3
5176
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 called DrawIndex. The DrawIndex is a combination autonumber index that uses the combination of these three fields WholesalerID, MagID, IssueID to ensure that each record is unique. When a used tries to enter data that has a the same WholesalerID,...
5
23058
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 that policy number is in the system when entering a new record. If it is, I want it to display a message and go back to the policy number field. I've tried this code on a policy number that is not in the table and it
0
1151
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 contains user descriptions and also has 2 fields: Type and UserDescription. This table lives in the back end database. The query shows all records in the front end table plus records where "Type" is equal. So basically the user can keep the default...
3
3476
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 directly to the second application in a browser, all of my events fire correctly. However, if I have the first application do a Response.Redirect to the second, for some reason none of my events on the second application ever get fired. After I...
5
4535
by: accessman2 | last post by:
Hi, I have a question. I made the create the new user form. <script language="javascript"> function submitFrm() {
5
1830
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 password in hidden form variables). display data page -approval page (bringing user name and password in hidden form variables. Also bringing disposition in
6
3597
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 to test if a "live" record exists in that table and if it does to let the user know that the record has not been written. The append query will only write the record to the table if one doesn't exist already. The criteria is emp_id and a field...
1
7280
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 and Brand I need to make some changes on a a number of brands in a Category
0
8352
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8802
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8465
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8579
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7297
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5612
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4144
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4283
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2699
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.