Jump to content

pass value from one page to another


jojay
 Share

Recommended Posts

Can someone tell how to pass a value from one page to another?I am trying to populate the form in form.asp and send those info to result.asp, dump into the database and response.write that info to the third page which is resultpage.asp. I am able to populate and send to database and it goes to resultpage.asp but it is not response.writing the info.result.asp

request.form fieldnamesconnection and recordset stringrs.open "Insert into table...."rs.open "Select Top 1 CID from cform Order BY CID Asc"new_id = rs.fields.item("CID").valuers.closecon.closeand set both = nothingresponse.redirect("resultpage.asp?CID = " & New_id)

resultpage.asp

CID = request.querystring("new_id")request.form formfieldsresponse.write formfields

My question is, should I have to create <form></form> and input fields to pass the values to the resultpage.asp. Anyway, I dont want to give a submit button in result.asp to pass the value to resultpage.asp. Any suggestins? Thanks.

Link to comment
Share on other sites

Jojay,Notice the code that you are using in result.asp:

response.redirect("resultpage.asp?CID = " & New_id)
And compare it to the code you're using in resultpage.asp:
CID = request.querystring("new_id")
The querystring you're sending and the querystring you're requesting don't match. Use this instead:
[results.asp]response.redirect("resultpage.asp?CID=" & New_id)[resultpage.asp]CID = request.querystring("CID")

By the way, you can get the ID of the last inserted query without having to execute another query like this:

Dim Conn, RS, SQL, LastInsertedIDSet Conn = Server.CreateObject("ADODB.Connection")Set RS = Server.CreateObject("ADODB.Recordset")Conn.Open your_connection_string	rs.CursorLocation = AdUseClient	sql1 = "Select * From Your_Table Where 0=1"	rs.Open sql1,conn, adOpenStatic, adLockOptimistic   RS.AddNew  rs("Field1")	= Field1_Value  rs("Field2")	= Field2_Value  rs("Field3")	= Field3_Value  rs("Field4")	= Field4_Value  rs("Field5")	= Field5_Value  RS.Update  LastInsertedID = rs("CID")	RS.closeConn.Closeresponse.redirect "resultpage.asp?CID=" & LastInsertedID

After you update your record, and before you close your record, you can assign a LastInsertedID = rs("ID") to get the ID of the field you've just inserted, without having to execute another sql statment.

Link to comment
Share on other sites

result.asp
Dim Conn, RS, SQL, LastInsertedIDSet Conn = Server.CreateObject("ADODB.Connection")Set RS = Server.CreateObject("ADODB.Recordset")Conn.Open your_connection_string	rs.CursorLocation = AdUseClient ' this also gives error so I removed that line	sql1 = "Select * From Your_Table Where 0=1"	rs.Open sql1,conn, 3,3  RS.AddNew  rs("Field1")	= Field1_Value  rs("Field2")	= Field2_Value  rs("Field3")	= Field3_Value  rs("Field4")	= Field4_Value  rs("Field5")	= Field5_Value  RS.Update  LastInsertedID = rs("CID")	RS.closeConn.Closeresponse.redirect "resultpage.asp?CID=" & LastInsertedID

[resultpage.asp]

CID = request.querystring("CID")

I used the above code and I modified some places like the adopenstatic and adlockoptimisitc becoz it is not letting me update and getting an error message such as "Arguement are not same or in conflict to each other"...The above code works fine sending the info into the database but at resultpage.asp, it is not passing still.
Link to comment
Share on other sites

I used the above code and I modified some places like the adopenstatic and adlockoptimisitc becoz it is not letting me update and getting an error message such as "Arguement are not same or in conflict to each other"...The above code works fine sending the info into the database but at resultpage.asp, it is not passing still.

Jojay, theres nothign wrong with the code I wrote, because its a copy/paste from one my own sites. However I made the presumption that you were using ADOVBS.inc (most ASP programmers include that file at the top of their pages by default). Without that file, ASP won't recognize some of the constants like AdUseClient and so on.See 4GuysFromRolla FAQ - ADOVBS.inc, its a good thing to get in the habit of using ADOVBS.inc. Just copy this text file to your root directory (save it as adovbs.inc or adovbs.asp), and add <!--#include file="adovbs.inc"--> to the top of any page that uses ADO, and then the code I wrote above will work.
Link to comment
Share on other sites

Jojay, theres nothign wrong with the code I wrote, because its a copy/paste from one my own sites. However I made the presumption that you were using ADOVBS.inc (most ASP programmers include that file at the top of their pages by default). Without that file, ASP won't recognize some of the constants like AdUseClient and so on.See 4GuysFromRolla FAQ - ADOVBS.inc, its a good thing to get in the habit of using ADOVBS.inc. Just copy this text file to your root directory (save it as adovbs.inc or adovbs.asp), and add <!--#include file="adovbs.inc"--> to the top of any page that uses ADO, and then the code I wrote above will work.

Yahweh,I tried and it didnt work. I have a copy of it in my folder but I am assuming that it should be used only when using heavy coding......anyway, that didnt help.here is my error:ADODB.Recordset error '800a0bb9'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. it points to line 39 which is :
rs.CursorLocation = AdUseClient

If I comment that line, then the error is going to:

rs.Open sql1, con, adOpenStatic, adLockOptimisitic

Now, the error is showing up in result.asp and data is not inserting to the database.I really dont know what is causing my problem not passing the value.

Link to comment
Share on other sites

Yahweh,I tried and it didnt work. I have a copy of it in my folder but I am assuming that it should be used only when using heavy coding......anyway, that didnt help.here is my error:ADODB.Recordset error '800a0bb9'Arguments are of the wrong type, are out of acceptable range, or are in conflict with one another. it points to line 39 which is :
rs.CursorLocation = AdUseClient

If I comment that line, then the error is going to:

rs.Open sql1, con, adOpenStatic, adLockOptimisitic

Now, the error is showing up in result.asp and data is not inserting to the database.I really dont know what is causing my problem not passing the value.

Hmmm...I haven't the faintest clue why the code isn't working. However, if it's giving you problems, then just go back to executing two seperate queries like you were doing originally.However, make sure when you response.redirect "resultpage.asp?cid=something", you request("CID") on your resultpage.asp to get the passed value.
Link to comment
Share on other sites

Hmmm...I haven't the faintest clue why the code isn't working. However, if it's giving you problems, then just go back to executing two seperate queries like you were doing originally.However, make sure when you response.redirect "resultpage.asp?cid=something", you request("CID") on your resultpage.asp to get the passed value.

Hi,I finally got the querystring working. According to your code, adOpenStatic, adLockoptimistic, was not getting the values from adovb.inc in my case, so I included the const adOpenStatic as 3 and adLockoptimistic as 3 and adUseClient as 3 as declaration and then used them in rs.open, it worked. What is the difference between this:
rs.open sql1,con,3,3

and this:

const adUseClient = 3const adOpenStatic = 3const adLockOptimisitic = 3set connset rsrs.open sql1, adOpenStatic, adLockOptimistic

Because in my opinion, in the first case, using the const directly without declaring. In the second case, it is declaring and using them. Please correct if I am wrong. Would like to know the difference? My next question, now the querystring is working but still not able to bring all my data to the resultpage.asp. Should I open the connection and using rs, bring the data from the database or just use response.write(fieldname) and pass the data. Confused.

Link to comment
Share on other sites

Hi,I finally got the querystring working. According to your code, adOpenStatic, adLockoptimistic, was not getting the values from adovb.inc in my case, so I included the const adOpenStatic as 3 and adLockoptimistic as 3 and adUseClient as 3 as declaration and then used them in rs.open, it worked. What is the difference between this:
rs.open sql1,con,3,3

and this:

const adUseClient = 3const adOpenStatic = 3const adLockOptimisitic = 3set connset rsrs.open sql1, adOpenStatic, adLockOptimistic

Because in my opinion, in the first case, using the const directly without declaring. In the second case, it is declaring and using them. Please correct if I am wrong. Would like to know the difference?

There's no difference at all, both work just the same. The only difference is the readability of your code (I personally like to see "adOpenStatic" as opposed to "3", its more descriptive).
My next question, now the querystring is working but still not able to bring all my data to the resultpage.asp. Should I open the connection and using rs, bring the data from the database or just use response.write(fieldname) and pass the data. Confused.

I apologize, but I don't know what you're asking, or what you're trying to get your script to do.
Link to comment
Share on other sites

There's no difference at all, both work just the same. The only difference is the readability of your code (I personally like to see "adOpenStatic" as opposed to "3", its more descriptive).I apologize, but I don't know what you're asking, or what you're trying to get your script to do.

No problem. I fixed it and it works perfectly. Thankyou. And thanks for explaining the difference.
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...