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

Question about sending a string to another page

Status
Not open for further replies.

Magnus53

Programmer
Jul 25, 2002
73
0
0
CA
Hi everyone,

I have two ASP pages, one has a form that the user can enter data into. The second creates a connection to a SQL server database then creates a html table with the data and sends it back to the first page as a string. I'm using a Session variable to pass the SQL string from the first page to the second one. My problem is that I can't get anything to return back to the first page, even if I hard code the string value. Here is my code. I hope I explained this well enough.

First Page:
Code:
<%@LANGUAGE=&quot;VBSCRIPT&quot; CODEPAGE=&quot;1252&quot;%>
<!--#include virtual=&quot;/mgt/includes/createTable.asp&quot;-->
<% on error resume next %>

<%

'Page Variables
Dim str_SQL					'SQL statement to execute '
Dim str_consID				'Consultant ID
Dim str_prodName			'Product Name
Dim sqlData 
Dim numRecs

' Purpose: Establish recordset
' Parameters: None
' Returns: None
Sub createSQLString()
	' Get the user inputs and build sql string
	Call getInputs()
	str_SQL = 	&quot; SELECT order_summary.cons_id, order_summary.ordr_num, order_summary.ordr_inv_id, order_summary.orty_code,&quot; & _ 
				&quot; product.prod_num, product.prod_name_engl, order_item.oitm_qty_ordered, order_item.oitm_price_amt,&quot; & _ 
				&quot; order_summary.ordr_eff_date, order_summary.ordr_add_date&quot; & _
				&quot; FROM order_summary&quot; & _
				&quot; INNER JOIN order_item ON order_summary.ordr_num = order_item.ordr_num&quot; & _ 
				&quot; INNER JOIN product ON order_item.prod_num = product.prod_num&quot; & _ 
				&quot; WHERE (((order_summary.cons_id) Like &quot; & &quot;'&quot; & &quot;%&quot; &  str_consID & &quot;%&quot; & &quot;'&quot;  & &quot;)&quot; & _
				&quot; AND ((product.prod_name_engl)  Like &quot; & &quot;'&quot; & &quot;%&quot;  & str_ProdName & &quot;%&quot; & &quot;'&quot;  & &quot;))&quot;
	
End Sub

' Purpose: Get the user inputed values
' Parameters: None
' Returns: None
Sub getInputs()

	'get the values from the text boxes
	str_consID 		= Trim(Request.Form(&quot;consID&quot;))
	str_prodName 	= Trim(Request.Form(&quot;prodName&quot;))

End Sub

Sub createSessionVars()
	
	SESSION(&quot;STRSQL&quot;) = str_SQL
	Response.Write(&quot;Session: &quot; & SESSION(&quot;STRSQL&quot;))
	
End Sub

' Purpose: Call all other subs
Sub process()

	Call createSQLString()
	createSessionVars()
	
End Sub
%>

<% process() %>

<html>
<head>
<title>Listing by Consultant ID and Product Name</title>
<meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=iso-8859-1&quot;>
</head>
<body>

<form action=&quot;&quot; method=&quot;post&quot; enctype=&quot;application/x-[URL unfurl="true"]www-form-urlencoded&quot;>[/URL]
  
  <table width=&quot;300&quot; border=&quot;0&quot;>
    <tr>
	<td colspan=&quot;2&quot;><font size=&quot;2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;>Please enter the following:</font></td>
	<td></td>
	</tr>
	<tr> 
      <td><font size=&quot;2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;>Consulant ID</font></td>
      <td><font size=&quot;2&quot; face=&quot;Verdana, Arial, Helvetica, sans-serif&quot;>Product Name</font></td>
    </tr>
    <tr> 
      <td><input name=&quot;consID&quot; 		type=&quot;text&quot; size=&quot;25&quot; maxlength=&quot;25&quot;></td>
      <td><input name=&quot;prodName&quot; 	type=&quot;text&quot; size=&quot;25&quot; maxlength=&quot;25&quot;></td>
    </tr>
    <tr align=&quot;center&quot;> 
      <td colspan=&quot;2&quot;> 
        <input name=&quot;submit&quot; type=&quot;submit&quot;>
      </td>
    </tr>
  </table>
</form>

<%	
	Response.Write(sql)
	Response.Write(&quot;Consultant: &quot; & str_consID & &quot;<br>&quot;)
	Response.Write(&quot;Product: &quot; & str_prodName & &quot;<br>&quot;)
	Response.Write(&quot;Records Returned: &quot; & numRecs & &quot;<br>&quot;)
%>
<br>
<div align=&quot;left&quot;>
<%=createTable()%>
</div>

</body>
</html>

Second Page:
<%

Option Explicit
Function createTable
	Dim sql
	Dim sqlData 
	Dim numRecs
	
	Dim i
	Dim j
	Dim numRows
	Dim numCols
	Dim fontsize
	Dim border
	Dim strTable
	Dim xsize 
	
	sql = SESSION(&quot;STRSQL&quot;)
	
	'create the ADO Connection and Recordset objects '
	' make connection to the SQL Server
	Set obj_conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
	obj_conn.Open &quot;DSN=opstest;UID=opstest;PWD=opstest;DATABASE=opstest&quot;
	
	Set obj_recordset = Server.CreateObject(&quot;ADODB.Recordset&quot;)
	obj_recordset.CursorLocation = 3 'adUseClient '
	obj_recordset.Open sql, obj_conn, 3 'adOpenStatic '

	' Check for any errors
	If err.number <> 0 Then
		 TrapError Err.description
	End If
	
	fontsize = 1
	border = 1
	xsize = 300
	
	numRows = UBound(sqlData, 2)
	numCols = UBound(sqlData, 1)
				
	sqlData = obj_recordset.GetRows()
	numRecs = UBound(sqlData, 2)
	''''''''''''''''''''''''''''''
	'  Column headings first row '
	''''''''''''''''''''''''''''''
	strTable = &quot;<TABLE>&quot;
	for i = 0 to numRows
		strTable = strTable & &quot;<TR>&quot;
		for j = 0 to numCols
			strTable = strTable &  &quot;<TD><FONT SIZE='&quot; & fontsize & &quot;'>&quot; & sqlData(j,i) & &quot;</FONT></TD>&quot;
		next
		strTable = strTable & &quot;</TR>&quot;
	next
	
	strTable = strTable & &quot;</TABLE>&quot;
	createTable = strTable 
End Function
%>
 
The only thing which readily comes to mind...don't always assume that a string which is populated in a sub or function will be available outside of the sub or function...merge the createSQLString and createSessionVars...
 
Without reading all of your code, I have a question about your method. Why are you loading all of this HTML into a session variable? If you have site that has more than a few visitors, you will be taxing the RAM of your server as you try to store session pages for each visitor.

I am also wondering why you don't just use the second page to response.write your output. It sounds like you might be best off combining the two into one page - a form that submits to itself.

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rich Cook
 
Hi guys,

I fixed, it was some very stupid errors on my part. Thanks for the reply's.

mwolf00

I'm not loading the html into a session variable, I have a function that returns the string that will create a table. I was trying to return the string but nothing was happing. I'm not worried about session variable as this is for intranet use only, but your right about what you said. I think I might change that part.

The second page is really only a tool, that'll create a html table from any query, so then all I have to do is pass it a sql statement and get a table back.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top