Go to Post I don't care if you use hot dogs for wheels. If you're scoring points, and you fit the strategy, it's fine. - evanperryg [more]
Home
Go Back   Chief Delphi > Technical > IT / Communications > Website Design/Showcase
CD-Media   CD-Spy  
portal register members calendar search Today's Posts Mark Forums Read FAQ rules

 
Closed Thread
 
Thread Tools Rate Thread Display Modes
  #1   Spotlight this post!  
Unread 13-06-2003, 11:00
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
ASP / HTML Links

Is there a way to determine if a user clicks on a link, and if so, update a file / database?

Also, this is more geared to ASP: If you already have an SQL query executed, how can you do another?

Example:
PHP Code:
<%
Set MyConn Server.CreateObject("ADODB.Connection")
MdbFilePath Server.MapPath("directory\to\database\file.mdb")
MyConn.Open "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" MdbFilePath ";"
SQL_query "SELECT * FROM files"
Set RS MyConn.Execute(SQL_query)
%> 
How would I be able to run another SQL query (like UPDATE)?
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #2   Spotlight this post!  
Unread 13-06-2003, 11:37
Trashed20's Avatar
Trashed20 Trashed20 is offline
Boom, Shawalala Boom!
#0862 (PCEP Lighting)
 
Join Date: Jan 2002
Location: Canton, MI
Posts: 528
Trashed20 will become famous soon enough
Send a message via AIM to Trashed20
well, since you already have your connection open couldn't you just make another query and execute it? I'm assuming this sorta behaves like php, but i may be wrong
__________________
Where has all the fun gone?
  #3   Spotlight this post!  
Unread 13-06-2003, 11:42
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Quote:
Originally posted by Trashed20
well, since you already have your connection open couldn't you just make another query and execute it? I'm assuming this sorta behaves like php, but i may be wrong
Already tried that before, the error that comes up is this:

"Cannot execute RS, it's already opened"

Not exactly like that, but close to it.
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #4   Spotlight this post!  
Unread 13-06-2003, 11:48
Trashed20's Avatar
Trashed20 Trashed20 is offline
Boom, Shawalala Boom!
#0862 (PCEP Lighting)
 
Join Date: Jan 2002
Location: Canton, MI
Posts: 528
Trashed20 will become famous soon enough
Send a message via AIM to Trashed20
have you tried to change the variable name to RS1 or something of that nature? I'm not exactly sure how ASP handles queries. It may still be trying to get things and continues with the code. THe only other thing i could suggest is close the connection and then open it again, but that seems like a really stupid way to do it.
__________________
Where has all the fun gone?
  #5   Spotlight this post!  
Unread 13-06-2003, 11:49
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Quote:
Originally posted by Trashed20
have you tried to change the variable name to RS1 or something of that nature? I'm not exactly sure how ASP handles queries. It may still be trying to get things and continues with the code. THe only other thing i could suggest is close the connection and then open it again, but that seems like a really stupid way to do it.
Tried both. I know there's a way to do it, I found a tutorial on it before, but lost the link...*ashamed* I should check my History */ashamed*
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #6   Spotlight this post!  
Unread 13-06-2003, 12:04
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
It might be that the connection opened using the Jet provider can't handle a recordset and an update query at the same time. Just use an implicit connection like this:

Code:
Set MyConn = Server.CreateObject("ADODB.Connection")
	Set RS = Server.CreateObject("ADODB.Recordset")
	
	connectString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
	MdbFilePath = Server.MapPath("directory\todatabasefile.mdb")
	
	'open the recordset
	SQL_query = "SELECT * FROM files"
	RS.Open SQL_query, connectString
	
	'run the update query
	SQL_query = "UPDATE myTable SET myField = 'foo'"
	MyConn.Open connectString
	MyConn.Execute SQL_Query
If you're running SQL you should ALWAYS use parameterized queries or stored procedures. SQL injection is the easiest way for people to completely screw up your database.
  #7   Spotlight this post!  
Unread 13-06-2003, 12:17
Raven_Writer's Avatar
Raven_Writer Raven_Writer is offline
2004 Detroit & Pittsburgh Winners
AKA: Eric Hansen
FRC #0005 (RoboCards)
Team Role: Mentor
 
Join Date: Jan 2003
Rookie Year: 2002
Location: Melvindale
Posts: 1,549
Raven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really niceRaven_Writer is just really nice
Send a message via ICQ to Raven_Writer Send a message via AIM to Raven_Writer Send a message via MSN to Raven_Writer Send a message via Yahoo to Raven_Writer
Quote:
Originally posted by seanwitte
It might be that the connection opened using the Jet provider can't handle a recordset and an update query at the same time. Just use an implicit connection like this:

Code:
Set MyConn = Server.CreateObject("ADODB.Connection")
	Set RS = Server.CreateObject("ADODB.Recordset")
	
	connectString = "Driver={Microsoft Access Driver (*.mdb)}; DBQ=" & MdbFilePath & ";"
	MdbFilePath = Server.MapPath("directory\todatabasefile.mdb")
	
	'open the recordset
	SQL_query = "SELECT * FROM files"
	RS.Open SQL_query, connectString
	
	'run the update query
	SQL_query = "UPDATE myTable SET myField = 'foo'"
	MyConn.Open connectString
	MyConn.Execute SQL_Query
If you're running SQL you should ALWAYS use parameterized queries or stored procedures. SQL injection is the easiest way for people to completely screw up your database.
Ok, that works decent...except this error:
Code:
Microsoft OLE DB Provider for ODBC Drivers error '80040e4e' 

Operation was canceled. 

/qtheory/conn.asp, line 9
All the paths are correct, it just deals with this line:
Code:
RS.Open SQL_query, connectString
Also, does anyone know the answer to my first question?
__________________
AIM: wisprmylastbreth
EMail: nightskywriter@gmail.com
Y!: synsoflife

"ai yoru ga" -- "Love the nights"
  #8   Spotlight this post!  
Unread 13-06-2003, 12:41
seanwitte seanwitte is offline
Registered User
None #0116
Team Role: Engineer
 
Join Date: Nov 2002
Location: Herndon, VA
Posts: 378
seanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant futureseanwitte has a brilliant future
Send a message via AIM to seanwitte
odd

I tried it again quickly and it works fine using only one connection. When you use connection.Execute() it returns a forward-only read-only cursor, so the connection should still be able to service other calls. I'm pretty sure its just with Jet though, it works ok here on SQL Server.

Back to your first question. Say you want to let people vote in a poll. You have a table called VOTE with a poll_id pointing to the poll and a code for what they voted for, names vote_code. When you write the links to the screen, use querystrings appended to the URL and point them back to the same page:

page filename: poll.asp

Code:
Poll Response Links:
<A HREF="poll.asp?poll_id=1&vote_code=A">Vote for A</A>
<A HREF="poll.asp?poll_id=1&vote_code=B">Vote for B</A>
<A HREF="poll.asp?poll_id=1&vote_code=C">Vote for C</A>
In the header of poll.asp you need to intercept and handle that request. the querystring values are part of a collection hanging off of the Request intrinsic object. This is bad, but it will work:

Code:
<%'local functions
	sub SaveVote(conn, poll, vote, userIP)
		dim sql
		sql = "INSERT INTO VOTE (poll_id, vote_code, user_ip) " & _
		      "VALUES(" & poll & ", '" & vote & "', '" & userIP & "')"
		conn.Execute sql		
	end sub
	
	'variable declarations
	dim connString
	dim connection
	dim pollID
	dim voteCode
	dim IP
	
	'grab any incoming data
	pollID = Request.QueryString("poll_id")
	voteCode = Request.QueryString("vote_code")
	IP = Request.ServerVariables("REMOTE_ADDR")
		
	'validate the data. the poll_id is an integer
	'and the voteCode is a one character value
	if not isNumeric(pollID) then pollID = ""
	if len(voteCode) > 1 then voteCode = ""
	
	'if both the poll_id and vote_code are empty then 
	'redirect to the poll selection page
	if pollID = "" and voteCode = "" then 
		Response.Redirect "poll_list.asp"
		Response.End
	end if
	
	'open a database connection
	connection.Open connString
		
	'if the vote_code is not empty then log the vote	
	if  voteCode <> "" then
		SaveVote connection, pollID, voteCode, IP			
	end if
	
	'get the poll info and render the page
%>

Last edited by seanwitte : 13-06-2003 at 12:59.
Closed Thread


Thread Tools
Display Modes 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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Any good HTML editors available? PMGRACER Website Design/Showcase 23 07-06-2003 21:02
NASA-TV links for Regionals Broadcasts archiver 2001 1 24-06-2002 01:59
What's better, PERL/cgi or PHP/my_sql? mikefrei Programming 10 27-05-2002 22:50
Webcast Links! Post links here! activemx Championship Event 0 21-04-2002 22:33
Rookie needs helpful programming links :) DanL Programming 15 23-02-2002 20:39


All times are GMT -5. The time now is 01:44.

The Chief Delphi Forums are sponsored by Innovation First International, Inc.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
Copyright © Chief Delphi