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 Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

insert into database in the same page as results displayed

Status
Not open for further replies.
Nov 29, 2002
64
US
Hello, can you execute an insert into command by clicking on a link / button, etc... without having to send it to a new .asp page?
I have 2 .asp pages:

Page1.asp shows some database data and requests some values using a form.

Page2.asp shows the same database data and performs some calculations on the data based on the values provided by the user on page1.asp.

What I need is a link that gives me the option to insert the results from this page in the database if the user agrees. I have the update code and works fine, but I don't know how to offer the validation option in the same page.asp. Can I do it??? Some "OnClick" function to continue with the vbscript code??

Thanks!
 
capture the value of the submit button at the top of the page and process accordingly. use post for the form method and leave action blank to submit the form to itself

Code:
if request.form("buttonname") = buttonvalue then
' do something
end if

'rest of page


Chris.

Indifference will be the downfall of mankind, but who cares?
 
Thanks ChrisHirst, this option works fine, when I click on the button, it saves the data to the database.

However, when sending the parameters from page 1 (user form) to page 2 (result display & save to DB), the data is automatically saved anyways, so I have now two records....

I forgot to mention, than among the data displayed on page 2, I have several fields that I obtain from a query to the same database.

this is what I have:
Code:
<% 
    set rsExon=Server.CreateObject("ADODB.Recordset")
    rowCount=0
    
    on error resume next

    'requesting from input from the user
	
	form_tdc=request.form("id")
	form_porcexon=request.form("porcexon")
	form_fechapago=request.form("T1")
	form_nrocuotas=CInt(request.form("nrocuotas"))
	form_periodo=request.form("periodo")

  'connnecting 
   strProvider="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("Exon_ODS.mdb")

  'first SQL query
    rsExon.Open "SELECT A, B,... FROM TABLE1 INNER JOIN TABLE2 ON .... WHERE TDC LIKE '" & form_tdc & "'", strProvider, , , adCmdText

  'get results
	form_nacext=rsExon("NACEXT")
	form_cedula=rsExon("CEDULA")
......

  'calculations
    form_montoexon= form_saldoT * form_porcexon/100
    form_saldorest= form_saldoT - form_montoexon
.....
  'close first query
    rsExon.close

  'open the second query, this is the INSERT INTO query

  if request.form("grabar") = buttonvalue then
	
	form_tdc=Replace(form_tdc,"'","' '")
	form_porcexon=Replace(form_porcexon,"'","' '")
....
 	rsExon.Open "INSERT INTO TABLE2 (NRO_CUENTA, PORC_EXON, SALDO_TOTAL, ......) VALUES ('" & form_tdc & "','" & form_porcexon & "','" & form_saldoT & "',....')", strProvider, , , adCmdText

'check for errors

If  err.number>0 then .....

else
response.write "<B>SAVED</B>"
    end if
	end if
	   
    rsExon.close
    set rsExon=nothing
%>

form 
table to display results etc etc...

Sould I put the code you suggested at the very top? Then, will it show the results before I press the button to validate and save???? Thanks!
Alfredo
 
Thanks ChrisHirst, this option works fine, when I click on the button, it saves the data to the database.

However, when sending the parameters from page 1 (user form) to page 2 (result display & save to DB), the data is automatically saved.

I forgot to mention, than among the data displayed on page 2, I have several fields that I obtain from a query to the same database.

this is what I have:
Code:
<% 
    set rsExon=Server.CreateObject("ADODB.Recordset")
    rowCount=0
    
    on error resume next

    'requesting from input from the user
	
	form_tdc=request.form("id")
	form_porcexon=request.form("porcexon")
	form_fechapago=request.form("T1")
	form_nrocuotas=CInt(request.form("nrocuotas"))
	form_periodo=request.form("periodo")

  'connnecting 
   strProvider="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("Exon_ODS.mdb")

  'first SQL query
    rsExon.Open "SELECT A, B,... FROM TABLE1 INNER JOIN TABLE2 ON .... WHERE TDC LIKE '" & form_tdc & "'", strProvider, , , adCmdText

  'get results
	form_nacext=rsExon("NACEXT")
	form_cedula=rsExon("CEDULA")
......

  'calculations
    form_montoexon= form_saldoT * form_porcexon/100
    form_saldorest= form_saldoT - form_montoexon
.....
  'close first query
    rsExon.close

  'open the second query, this is the INSERT INTO query

  if request.form("grabar") = buttonvalue then
	
	form_tdc=Replace(form_tdc,"'","' '")
	form_porcexon=Replace(form_porcexon,"'","' '")
....
 	rsExon.Open "INSERT INTO TABLE2 (NRO_CUENTA, PORC_EXON, SALDO_TOTAL, ......) VALUES ('" & form_tdc & "','" & form_porcexon & "','" & form_saldoT & "',....')", strProvider, , , adCmdText

'check for errors

If  err.number>0 then .....

else
response.write "<B>SAVED</B>"
    end if
	end if
	   
    rsExon.close
    set rsExon=nothing
%>

form 
table to display results etc etc...

Sould I put the code you suggested at the very top? Then, will it show the results before I press the button to validate and save???? Thanks!
Alfredo
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top