-1

I have done coding in Classic ASP for selecting the two options through drop down and Submitting the selected value to update database. It is not working. I am using SQL Query in "../sqlConnection.asp" location which basically contains the query to update Database Value for Year and Season. I checked the database sql query in SQL server, SQL code works to update Year and Season. But just updating through Classic ASP is not working. Below is my code in Classic ASP:

Suggested Solution that worked:

I used action attribute in form tag. I had to do this in sql query asp file, here in my case ../sqlConnection.asp: PCE_Update.Open(sqlqry) and I had to include another asp file where connection strings were defined which I was missing.

Working Code - Edited Code following suggestions:

../Example.asp:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<% Option Explicit %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Project Site</title>
<link rel="stylesheet" href="../css/reports.css" type="text/css" />
<style type="text/css">

</style>
</head>

<!--#include file="../sqlConnection.asp" -->
    <!--#include file="../sqlConnection1.asp" -->   
         <%
Dim YearID
Dim SeasonID
Dim myStudentID
          YearID = Request.Form("dYear")
          SeasonID = Request.Form("dSeason")

If Request.ServerVariables("REQUEST_METHOD")= "POST" Then
          myID = Request.QueryString("uniqueid")
          Updatedate myID, YearID, SeasonID
  End If
         %>

<body>
<div align = "center">
    <div>
    <form id="form1" method="post" action="Example.asp<%= request.querystring %>">

    <select class="dropYear" name="dYear">
    <option value="select">2014</option>
    <option value="2015">2015</option>
     </select>

    &nbsp &nbsp &nbsp;

    <select class="dropSeason" name="dSeason">
    <option value="select">FALL</option>
    <option value="Winter">WINTER</option>
       </select>

    <br /><br />

     <ul class="buttons">
     <input id="save" method="post" class="btTxt" type="submit" value="Submit"; />

     </ul> 
     </form>
    </div>
    <br/>
      </div>
</body>
</html>

Here is my SQL query in "../sqlConnection.asp" which is being called from above code. This below SQL query works perfectly when I run in SQL Server, It updates year and season for particular employee id accordingly.

../sqlConnection.asp

Dim employeeid
Dim futureyear
Dim futureseason
Dim sqlquery
Dim PCE_Update
Dim sisconn
Sub Updatedate (employeeid,futureyear,futureseason)
sqlquery="update userdefinedind " & _
"set ayear = '" & futureyear & "' , aseason = '" & futureseason & "' " & _
"where employee_id = '" & employeeID & "' "

Response.Write(sqlquery)

    set PCE_Update = server.CreateObject("ADODB.Recordset")
        with PCE_Update
            .ActiveConnection = sisconn
            .CursorType = 1
            .CursorLocation = 2
            .Source = sqlqry
        end with    
        PCE_Update.Open(sqlqry)
end sub

Is there anything I am missing? Please suggest. I don't work much in Classic ASP and thought I might be missing simple step here.

TechPro
  • 331
  • 1
  • 10
  • 29
  • Unlike forum sites, we don't use "Thanks", or "Any help appreciated", or signatures on [so]. See "[Should 'Hi', 'thanks,' taglines, and salutations be removed from posts?](http://meta.stackexchange.com/questions/2950/should-hi-thanks-taglines-and-salutations-be-removed-from-posts). – John Saunders Nov 11 '14 at 20:34
  • I didn't know this. I will remove it @JohnSaunders. Thank you for letting me know. – TechPro Nov 11 '14 at 20:35

2 Answers2

1

Since you are not using action , page got posted back to currect page, but without querystring .

But you are dependent on querystring for update operation - as you are using myID = Request.QueryString("uniqueid") and then using myID in update's where condition. Which means, myID, after postback , has null value, implies no update operation.

To make it work, update action attribute as action="index.asp?<%= request.querystring %>"

Replace index.asp with required value.

Read more - Post to current page, keeping querystring values in tact

EDIT 1

I was telling to add action to <form .. tag. Like following.

<form id="form1" method="post" action="example.asp?<%= request.querystring %>">

I believe,<input.. tag does not have any action attribute.

EDIT 2

You need to check, if there is post event, then only invoke update method, so to do that, you need to wrap those into if check, like following.

<%
If Request.ServerVariables("REQUEST_METHOD")= "POST" Then
          YearID = Request.Form("dYear")
          SeasonID = Request.Form("dSeason")

          myID = Request.QueryString("uniqueid")
          Updatedate myID, YearID, SeasonID
End If
%>
Community
  • 1
  • 1
Arindam Nayak
  • 7,346
  • 4
  • 32
  • 48
  • I made change as you suggested. I believe you asked to use action attribute in Submit Button as I edited in above code? It still doesn't work. Any idea what I am missing now? – TechPro Nov 11 '14 at 20:55
  • @TechPro, Updated by answer, have a look at it. I was telling to add `action` to `form` tag. – Arindam Nayak Nov 12 '14 at 05:48
  • @TechPro No you've added `action` to the `` tag this is not correct, go back and remove `action` from `` and add it to the `
    ` tag. See [Arindam's edit](http://stackoverflow.com/revisions/26873797/2).
    – user692942 Nov 12 '14 at 11:47
  • @ArindamNayak: I did update the action attribute and added it to
    tag. Now I am getting another error in .asp file where sql query exists and being called. This is the error I am getting: ADODB.Recordset error '800a0bb9' . Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. Any idea on this one?
    – TechPro Nov 13 '14 at 14:02
  • @TechPro , you need to check `sql` query constructed in `Updatedate`, may be debug or put response.write to check , what is the query generated, and execute same query in sql , check if still that executes! – Arindam Nayak Nov 13 '14 at 14:57
  • @ArindamNayak: I added Response.Write(sqlquery) in my sql query code, Now in output I can see this result: Update userdefinedind set ayear = '' , aseason = '' where employee_id = '123456' For some reason my code to get the form values YearID = Request.Form("dYear") SeasonID = Request.Form("dSeason") is not working as I am getting empty value for year and season in sql query. But it is getting employee_id. hmm now wondering what I am missing, why it's not getting form value. – TechPro Nov 13 '14 at 15:52
  • @TechPro , updated answer, check that, - you need to invoke this only on page post , else you will always get blank value for `request.form`. – Arindam Nayak Nov 13 '14 at 16:35
  • 1
    @ArindamNayak: Your answer helped me to get correct selected dropdown value in query. Now in output I can see this result: Update userdefinedind set ayear = '2015' , aseason = 'Fall' where employee_id = '123456'. But this error is still showing with error in line 15, i.e..ActiveConnection = sisconn this line of code. Error is: ADODB.Recordset error '800a0bb9'. Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. This error is driving me crazy. Any idea again? – TechPro Nov 13 '14 at 17:31
  • @TechPro , I think, atleast this solved 1st part of problem, if you think so - http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work, mark as answer and regarding errors you need to check other answers for this -http://stackoverflow.com/questions/8428704/adodb-recordset-error-800a0bb9-arguments-are-of-the-wrong-type, http://stackoverflow.com/questions/19936293/adodb-recordset-error-800a0bb9-arguments-are-of-the-wrong-type-are-out-of-acc – Arindam Nayak Nov 13 '14 at 17:36
  • @ArindamNayak: Issue resolved. I have updated the code above. I had to do this in sql query asp file: PCE_Update.Open(sqlqry) and I had to include another asp file where connection strings were defined which I was missing. I really appreciate all your help. – TechPro Nov 13 '14 at 20:49
0

There's no action attribute in the code you've posted. Have you tried adding an explicit action (page to post the data to)?

Your submit button is also outside your closing form tag.

EDIT

You have your variables declared in your HTML form, not the ASP page that's doing the processing. Move these to your processing page:

 <%
  YearID = Request.Form("dYear")
  SeasonID = Request.Form("dSeason")

  myID = Request.QueryString("uniqueid")
  Updatedate myID, YearID, SeasonID
 %>

Then call your update method:

Updatedate(myID, yearID, seasonID)

You need to do this in the page that actually does the processing, or the variable values will be lost.

I think you also need to move the Action attribute from the submit button to the form tag.

Tim
  • 4,051
  • 10
  • 36
  • 60
  • Tim - `submit` button is inside closing form tag, and even if action is missing, still it will post to same page - http://stackoverflow.com/questions/14482356/post-to-current-page-keeping-querystring-values-in-tact – Arindam Nayak Nov 11 '14 at 20:24
  • 1
    There are two close form tags in the sample code and only one open tag (unless it's been edited). This isn't valid HTML and should really be cleaned up. – Tim Nov 11 '14 at 20:25
  • 1
    Yes, got it, agree too - need to clean up `HTML` as well – Arindam Nayak Nov 11 '14 at 20:26
  • Cleaned the missing form tag. I added Action Attribute in above edited code: It's still not working. Any idea what I am missing now? – TechPro Nov 11 '14 at 20:57
  • How about you update the code snippet so we can take a look at what you've done? – Tim Nov 11 '14 at 21:01
  • @Tim: I did update above code snippet. I have mentioned: Edited Code following suggestions: in above code. I used action attribute in Submit button, with post method. Am I doing correct? – TechPro Nov 11 '14 at 21:04
  • You know what, try adding <% Option Explicit %> to the top of your page. That will force variable declarations. I bet you've got a typo, and vbScript will create a variable when there's a typo instead of throwing an error. (That drove me nuts for years) – Tim Nov 11 '14 at 21:13
  • @Tim, I added <% Option Explicit %> as you suggested. I don't get any error regarding variable declaration. Still I am not being able to make this updating work. – TechPro Nov 11 '14 at 21:53
  • @Tim: As you mentioned, define variable in processing page. Are you saying processing page as the page where database query is used or the page from where update query is being called. I got confused here. I just have 2 pages both are .asp, ../Example.asp from where I am calling another asp page ../sqlConnection.asp where my query to update database exists. Please suggest. – TechPro Nov 12 '14 at 15:05
  • The way your code is written, you're declaring the variables in the form the user is filling out. Those are going to be passed to sqlRecordModifications.asp (in classic ASP if you don't use session variables, querystrings, or cookies, you can't persist a value across pages). I think the Request.form code should be in sqlRecordModifications.asp, which is where your form posts to. – Tim Nov 12 '14 at 15:12
  • @Tim: Sorry for confusion, I have updated the file name in above code, The form tag is in Example.asp itself and form posts to Example.asp itself so, using Form.Request code in Example.asp , and after getting the form values and querystring values calling SQL query file ../sqlConnection.asp to update the values. I have put the Request.form code in just above body part. Is it correct way I am doing? I am now getting variable undefined error in asp page where sql query exists. – TechPro Nov 12 '14 at 15:28
  • Declare the variables and you should be all set. – Tim Nov 12 '14 at 15:30
  • @Tim: I did declare variable in ../sqlConnection.asp above code. But now I am gettting different error saying: ADODB.Recordset error '800a0bb9' Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. Getting error for this line of code: .ActiveConnection = sisconn Any idea on this one? – TechPro Nov 12 '14 at 16:12
  • Try response.writing the connectionstring out to make sure it's the value you expect. – Tim Nov 12 '14 at 16:17
  • @Tim: I believe I need to do response.write command but where should I use this response.write? in asp file where my database query is there or in asp page where my form exists. Can you please guide me on this one? I have never used response.write before. Can you please provide me example how I can do. I am not getting error in other applications that is using the same asp file where sql query exists and in same path. – TechPro Nov 12 '14 at 16:38
  • Add *response.write("sisconn")* right above your recordset object. – Tim Nov 12 '14 at 17:29
  • @Tim: It shows in output: sisconn ADODB.Recordset error '800a0bb9' Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. – TechPro Nov 12 '14 at 19:36
  • @Tim: I added Response.Write(sqlquery) in my sql query code, Now in output I can see this result: Update userdefinedind set ayear = '' , aseason = '' where employee_id = '123456' For some reason my code to get the form values YearID = Request.Form("dYear") SeasonID = Request.Form("dSeason") is not working as I am getting empty value for year and season in sql query. But it is getting employee_id. hmm now wondering what I am missing, why it's not getting form value. – TechPro Nov 13 '14 at 15:55
  • Check your spelling for the field names. – Tim Nov 13 '14 at 15:57
  • @Tim:I tried the solution the user ArindamNayak suggested, Now I am seeing query output as Update userdefinedind set ayear = '2015' , aseason = 'Fall' where employee_id = '123456'. But this error is still showing with error in line 15, i.e..ActiveConnection = sisconn this line of code. Error is: ADODB.Recordset error '800a0bb9'. Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. This error is driving me crazy. Any idea again? – TechPro Nov 13 '14 at 17:53
  • @Tim: Issue resolved. I have updated the code above. I had to do this in sql query asp file: PCE_Update.Open(sqlqry) and I had to include another asp file where connection strings were defined which I was missing. I really appreciate all your help. – TechPro Nov 13 '14 at 20:50