Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can't update record

Status
Not open for further replies.

Phailak

Programmer
Apr 10, 2001
142
0
0
CA
Hail,

I'm having problems updating my recordset. What I want to do is update my table Players with the data from the previous page using request.querystring and request.form. This is my code:

<%
sql = &quot;select * from Players WHERE UserID like '&quot; & ucase(request.querystring(&quot;Player&quot;)) & &quot;'&quot;
Set Conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
Conn.Open &quot;Gladiators&quot;, &quot;Glad&quot;, &quot;glad&quot;
Set rs = Server.CreateObject(&quot;ADODB.Recordset&quot;)
rs.cursortype = 2
rs.cursorlocation = 1
rs.locktype = 2
rs.Open sql, Conn
%>
<%
if not rs.eof then
rs(&quot;Race&quot;) = request.form(&quot;cmbRaces&quot;)
rs(&quot;ChrName&quot;) = request.form(&quot;txtChrName&quot;)
rs(&quot;Hit&quot;) = request.querystring(&quot;HIT&quot;)
rs(&quot;Par&quot;) = request.querystring(&quot;PAR&quot;)
rs(&quot;Dam&quot;) = request.querystring(&quot;DAM&quot;)
rs(&quot;Arm&quot;) = request.querystring(&quot;ARM&quot;)
rs(&quot;Lif&quot;) = request.querystring(&quot;LIF&quot;)
rs(&quot;Wil&quot;) = request.querystring(&quot;WIL&quot;)
rs(&quot;Cha&quot;) = request.querystring(&quot;CHA&quot;)
if request.form(&quot;cmbSkills&quot;) = &quot;Dive&quot; then
rs(&quot;Dive&quot;) = 1
elseif request.form(&quot;cmbSkills&quot;) = &quot;FirstStrike&quot; then
rs(&quot;FirstStrike&quot;) = 1
elseif request.form(&quot;cmbSkills&quot;) = &quot;Dodge&quot; then
rs(&quot;Dodge&quot;) = 1
elseif request.form(&quot;cmbSkills&quot;) = &quot;Fake&quot; then
rs(&quot;Fake&quot;) = 1
elseif request.form(&quot;cmbSkills&quot;) = &quot;DeathBlow&quot; then
rs(&quot;DeathBlow&quot;) = 1
elseif request.form(&quot;cmbSkills&quot;) = &quot;Acrobatics&quot; then
rs(&quot;Acrobatics&quot;) = 1
elseif request.form(&quot;cmbSkills&quot;) = &quot;Regenaration&quot; then
rs(&quot;Regenaration&quot;) = 1
elseif request.form(&quot;cmbSkills&quot;) = &quot;Taunt&quot; then
rs(&quot;Taunt&quot;) = 1
end if
rs.update
rs.close
end if
%>
 
You can't use request.querystring and request.form at the same time. You are either doing one or the other.
 
1. Normally you let users typ in information on a <FORM> with <INPUT> fields etc. Then they press the <INPUT type=SUBMIT> button (and you POST the information to a second form (or the same). Then you can query the enterd values by using REQUEST.FORM(<field>)

2. I never update a field like this (but who am i?). Create a cSQL string with the complete SQL-statement: like this:
cSQL = &quot;INSERT INTO TEST (field1, field2) VALUES('&quot; &_
request.form(&quot;fField1&quot;) & &quot;','&quot; &_
request.form(&quot;fField2&quot;) & &quot;')&quot;
Open a connection:
set conn = server.createobject(&quot;ADODB.Connection&quot;)
conn.open = &quot;<you know what>&quot;

Then you issue a:
conn.execute(cSQL)

and presto!

br
Gerard
 
Hail,

Thanx for the responses.
First, if I can't use both querystring and the form, is there another way to do the following.
The user must select four options from four Select boxes (this is where the request.form comes in right?) and on the same page, different stats are randomly obtained from a recordset and thrown into a table. When the user submits, I need the selected data from the four Select Boxes and the variables that were put into the table.

Second, If I use an INSERT statement, isn't that to add data, I want to update an existing record with the info I should get from above.

Phailak
 
Hail guys,

Thanx but I figured it out.
For your information, we can use both querystring and form on the request, maybe my question had simply been badly put.
And my update is fine now, I played with it a little and it works.

Thanx again for the help

Phailak
 
A few things I noticed...

First, I wouldn't use the &quot;like&quot; keyword in your SQL statement to match on userID. UserID should be a primary key and if so you should have an exact match. Using the Like keyword could throw you into some errors such as two userID's that are similar ie.. Me and MeToo &quot;like 'Me'&quot; would return both.

Second, although there is a performance hit, you can reference just the general request object and let it find the field for you. So instead of Request.Form(&quot;cmbRace&quot;) you could simply use Request(&quot;cmbRace&quot;). ASP has a defined priority (which I cant remember) that determines the collections it looks in and the order it does so.

Third, I think foxbox was saying not to use the Recordset object to update your database. Instead create a sql query instead of using RS.Update. This is for performance reasons also. If you do this, you wont need to specify cursorlocation, cursortype, locktype.

Finally, you should look into DSN-less connection strings. They are more efficient, makes your code more portable, and keeps you from messing with ODBC and the registry.

Good Luck
Eddy Dumire
eddy.dumire@knowledgecg.com
 
Hail,

Thanx for more good advice. I will keep this definatly in mind when comes the time for performence issues. For now I just want it to work, I just started using ASP and VBScript so I'm sure there's a lot of stuff I need to improve.

Phailak
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top