Hi guys i'm populating a dropdown list of customers from a table in my database. After a customer is selected, i'm going to another page that lists all the customers details. The problem i'm having is when the customer is selected and the form submitted, only the first customer in the table is displayed, not the actual customer that was selected. How do i pass the CustomerID (unique key) to the second page from a dropdown list??? here's the code.
===========================================================
First Page
===========================================================
<%@ LANGUAGE="VBSCRIPT" %>
<%
Option Explicit
Response.Buffer = True
Response.ContentType = "text/html; charset=iso-8859-1"
'------------------------------------------------------------------------------
'--- Module: .asp
'---
'--- Version: 1.0
'---
'--- Purpose:
'---
'--- Dependencies:
'---
'--- Notes:
'---
'--- Author: Gene Magerr genemagerr@hotmail.com
'--- Copyright 2001 Magerr Media all rights reserved
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
Dim cnCust, rsCust, strSQL, CustID
'------------------------------------------------------------------------------
'--- Declarations
'------------------------------------------------------------------------------
Set cnCust = Server.CreateObject("ADODB.Connection"
cnCust.Open "DSN=Telmon"
strSQL = "SELECT * FROM Customers"
Set rsCust = Server.CreateObject("ADODB.Recordset"
rsCust.Open strSQL, cnCust
'------------------------------------------------------------------------------
'--- Initialization
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'--- Body
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'--- Begin HTML output
'------------------------------------------------------------------------------
%>
<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
</HEAD>
<BODY>
<DIV align="center">
<P> <% If Request.Querystring = "NoCust" Then %>
<B><font face="Verdana, Arial, Helvetica, sans-serif">You must select a customer to continue!</font></B>
<% End If %>
</P>
<P>Select a Customer from the list<BR>
or<BR>
<A href="AddCust.asp">Add a new Customer</A></P>
<P>
<% If rsCust.EOF <> False Then
Response.Write "<table width='80%' align='center' cellspacing='0'><td align='center'><font face='Verdana, Arial, Helvetica, sans-serif' size='1'>There are currently no Customers<br>"
Response.Write "in the database</font></td></table><p>"
Else
%>
</DIV>
<FORM name="form1" method="post" action="SelectJob.asp">
<DIV align="center">
<SELECT name="Customer">
<option selected>
<% Do While Not rsCust.EOF
Response.Write("<OPTION value=""" & rsCust("CustCompanyName"
& """>" & rsCust("CustCompanyName"
& "</option>"
Session("CustID"
= rsCust.Fields.Item("CustomerID"
.Value
'use MoveNext to fetch the next record
rsCust.MoveNext
Loop
%>
</select>
<INPUT type="submit" name="Submit" value="Submit">
<INPUT TYPE="hidden" name="CustID" value="<%=Session("CustID"
%>">
</P>
<% End If %>
</DIV>
</FORM>
</BODY>
</HTML>
<%
'------------------------------------------------------------------------------
'--- End HTML Output
'------------------------------------------------------------------------------
rsCust.Close
Set rsCust = Nothing
cnCust.Close
Set cnCust = Nothing
'------------------------------------------------------------------------------
'--- All ASP post processing code goes here, as well as
'--- sub routines and functions
'------------------------------------------------------------------------------
%>
===========================================================
Second Page
===========================================================
<%@ LANGUAGE="VBSCRIPT" %>
<%
Option Explicit
Response.Buffer = True
Response.ContentType = "text/html; charset=iso-8859-1"
'------------------------------------------------------------------------------
'--- Module: .asp
'---
'--- Version: 1.0
'---
'--- Purpose:
'---
'--- Dependencies:
'---
'--- Notes:
'---
'--- Author: Gene Magerr genemagerr@hotmail.com
'--- Copyright 2001 Magerr Media all rights reserved
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
Dim cnCust, rsCust, strSQL, SiteID, Company, CustID
'------------------------------------------------------------------------------
'--- Declarations
'------------------------------------------------------------------------------
Response.Write Session("CustID"
Set cnCust = Server.CreateObject("ADODB.Connection"
cnCust.Open "DSN=Telmon"
strSQL = "SELECT * FROM Customers WHERE CustomerID=" & Session("CustID"
Set rsCust = Server.CreateObject("ADODB.Recordset"
rsCust.Open strSQL, cnCust
'------------------------------------------------------------------------------
'--- Initialization
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'--- Body
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'--- Begin HTML output
'------------------------------------------------------------------------------
%>
<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
</HEAD>
<BODY>
<% If Request.Form("Customer"
<> "" Then %>
<P> </P>
<TABLE width="75%" border="1" align="center" cellspacing="0" bordercolor="#006600">
<TR bgcolor="#CCFFCC">
<TD><DIV align="center">Name</DIV></TD>
<TD><DIV align="center">Address</DIV></TD>
<TD><DIV align="center">City </DIV></TD>
<TD><DIV align="center">State </DIV></TD>
<TD><DIV align="center">Zip</DIV></TD>
</TR>
<TR>
<TD height="23"><DIV align="center"><%=rsCust("CustCompanyName"
%></DIV></TD>
<TD><DIV align="center"><%=rsCust("CustAddress"
%></DIV></TD>
<TD><DIV align="center"><%=rsCust("CustCity"
%> </DIV></TD>
<TD><DIV align="center"><%=rsCust("CustState"
%></DIV></TD>
<TD><DIV align="center"><%=rsCust("CustZip"
%></DIV></TD>
</TR>
</TABLE>
<% Else
Response.Redirect "SelectCust.asp?NoCust"
End If %>
<P align="center">
<%
Session("Company"
= rsCust.Fields.Item("CustCompanyName"
.Value
rsCust.Close
Set rsCust = Nothing
Dim rsSite, strSQLSite
Set rsSite = Server.CreateObject("ADODB.Recordset"
strSQLSite = "SELECT * FROM JobSite WHERE CustomerID=" & Session("CustID"
rsSite.Open strSQLSite, cnCust
%>
Select JobSite for <%=Session("Company"
%><BR>
or<BR>
<A href="AddJob.asp?CustID=<%=Session("CustID"
%>">Enter
a new JobSite for</A> <%=Session("Company"
%></P>
<FORM name="form1" method="post" action="ListJob.asp">
<DIV align="center">
<SELECT name="Jobsite">
<OPTION selected>
<% Do While Not rsSite.EOF
Response.Write("<OPTION value=""" & rsSite("SiteCompanyName"
& """>" & rsSite("SiteCompanyName"
& "</option>"
Session("SiteID"
= rsSite.Fields.Item("JobSiteID"
.Value
'use MoveNext to fetch the next record
rsSite.MoveNext
Loop
%>
</SELECT>
<INPUT type="submit" name="Submit" value="Submit">
<INPUT type="hidden" name="SiteID" value="<%=Session("SiteID"
%>">
<INPUT type="hidden" name="CustID" value="<%=Session("CustID"
%>">
</DIV>
</FORM>
<P align="center"> </P>
<P align="center"> </P>
</BODY>
</HTML>
<%
'------------------------------------------------------------------------------
'--- End HTML Output
'------------------------------------------------------------------------------
cnCust.Close
Set cnCust = Nothing
'------------------------------------------------------------------------------
'--- All ASP post processing code goes here, as well as
'--- sub routines and functions
'------------------------------------------------------------------------------
%>
I'm going to go to a third page as well, but i need to get the ID passed before i can continue. Thanks
===========================================================
First Page
===========================================================
<%@ LANGUAGE="VBSCRIPT" %>
<%
Option Explicit
Response.Buffer = True
Response.ContentType = "text/html; charset=iso-8859-1"
'------------------------------------------------------------------------------
'--- Module: .asp
'---
'--- Version: 1.0
'---
'--- Purpose:
'---
'--- Dependencies:
'---
'--- Notes:
'---
'--- Author: Gene Magerr genemagerr@hotmail.com
'--- Copyright 2001 Magerr Media all rights reserved
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
Dim cnCust, rsCust, strSQL, CustID
'------------------------------------------------------------------------------
'--- Declarations
'------------------------------------------------------------------------------
Set cnCust = Server.CreateObject("ADODB.Connection"
cnCust.Open "DSN=Telmon"
strSQL = "SELECT * FROM Customers"
Set rsCust = Server.CreateObject("ADODB.Recordset"
rsCust.Open strSQL, cnCust
'------------------------------------------------------------------------------
'--- Initialization
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'--- Body
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'--- Begin HTML output
'------------------------------------------------------------------------------
%>
<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
</HEAD>
<BODY>
<DIV align="center">
<P> <% If Request.Querystring = "NoCust" Then %>
<B><font face="Verdana, Arial, Helvetica, sans-serif">You must select a customer to continue!</font></B>
<% End If %>
</P>
<P>Select a Customer from the list<BR>
or<BR>
<A href="AddCust.asp">Add a new Customer</A></P>
<P>
<% If rsCust.EOF <> False Then
Response.Write "<table width='80%' align='center' cellspacing='0'><td align='center'><font face='Verdana, Arial, Helvetica, sans-serif' size='1'>There are currently no Customers<br>"
Response.Write "in the database</font></td></table><p>"
Else
%>
</DIV>
<FORM name="form1" method="post" action="SelectJob.asp">
<DIV align="center">
<SELECT name="Customer">
<option selected>
<% Do While Not rsCust.EOF
Response.Write("<OPTION value=""" & rsCust("CustCompanyName"
Session("CustID"
'use MoveNext to fetch the next record
rsCust.MoveNext
Loop
%>
</select>
<INPUT type="submit" name="Submit" value="Submit">
<INPUT TYPE="hidden" name="CustID" value="<%=Session("CustID"
</P>
<% End If %>
</DIV>
</FORM>
</BODY>
</HTML>
<%
'------------------------------------------------------------------------------
'--- End HTML Output
'------------------------------------------------------------------------------
rsCust.Close
Set rsCust = Nothing
cnCust.Close
Set cnCust = Nothing
'------------------------------------------------------------------------------
'--- All ASP post processing code goes here, as well as
'--- sub routines and functions
'------------------------------------------------------------------------------
%>
===========================================================
Second Page
===========================================================
<%@ LANGUAGE="VBSCRIPT" %>
<%
Option Explicit
Response.Buffer = True
Response.ContentType = "text/html; charset=iso-8859-1"
'------------------------------------------------------------------------------
'--- Module: .asp
'---
'--- Version: 1.0
'---
'--- Purpose:
'---
'--- Dependencies:
'---
'--- Notes:
'---
'--- Author: Gene Magerr genemagerr@hotmail.com
'--- Copyright 2001 Magerr Media all rights reserved
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
Dim cnCust, rsCust, strSQL, SiteID, Company, CustID
'------------------------------------------------------------------------------
'--- Declarations
'------------------------------------------------------------------------------
Response.Write Session("CustID"
Set cnCust = Server.CreateObject("ADODB.Connection"
cnCust.Open "DSN=Telmon"
strSQL = "SELECT * FROM Customers WHERE CustomerID=" & Session("CustID"
Set rsCust = Server.CreateObject("ADODB.Recordset"
rsCust.Open strSQL, cnCust
'------------------------------------------------------------------------------
'--- Initialization
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'--- Body
'------------------------------------------------------------------------------
'------------------------------------------------------------------------------
'--- Begin HTML output
'------------------------------------------------------------------------------
%>
<HTML>
<HEAD>
<TITLE>Untitled</TITLE>
</HEAD>
<BODY>
<% If Request.Form("Customer"
<P> </P>
<TABLE width="75%" border="1" align="center" cellspacing="0" bordercolor="#006600">
<TR bgcolor="#CCFFCC">
<TD><DIV align="center">Name</DIV></TD>
<TD><DIV align="center">Address</DIV></TD>
<TD><DIV align="center">City </DIV></TD>
<TD><DIV align="center">State </DIV></TD>
<TD><DIV align="center">Zip</DIV></TD>
</TR>
<TR>
<TD height="23"><DIV align="center"><%=rsCust("CustCompanyName"
<TD><DIV align="center"><%=rsCust("CustAddress"
<TD><DIV align="center"><%=rsCust("CustCity"
<TD><DIV align="center"><%=rsCust("CustState"
<TD><DIV align="center"><%=rsCust("CustZip"
</TR>
</TABLE>
<% Else
Response.Redirect "SelectCust.asp?NoCust"
End If %>
<P align="center">
<%
Session("Company"
rsCust.Close
Set rsCust = Nothing
Dim rsSite, strSQLSite
Set rsSite = Server.CreateObject("ADODB.Recordset"
strSQLSite = "SELECT * FROM JobSite WHERE CustomerID=" & Session("CustID"
rsSite.Open strSQLSite, cnCust
%>
Select JobSite for <%=Session("Company"
or<BR>
<A href="AddJob.asp?CustID=<%=Session("CustID"
a new JobSite for</A> <%=Session("Company"
<FORM name="form1" method="post" action="ListJob.asp">
<DIV align="center">
<SELECT name="Jobsite">
<OPTION selected>
<% Do While Not rsSite.EOF
Response.Write("<OPTION value=""" & rsSite("SiteCompanyName"
Session("SiteID"
'use MoveNext to fetch the next record
rsSite.MoveNext
Loop
%>
</SELECT>
<INPUT type="submit" name="Submit" value="Submit">
<INPUT type="hidden" name="SiteID" value="<%=Session("SiteID"
<INPUT type="hidden" name="CustID" value="<%=Session("CustID"
</DIV>
</FORM>
<P align="center"> </P>
<P align="center"> </P>
</BODY>
</HTML>
<%
'------------------------------------------------------------------------------
'--- End HTML Output
'------------------------------------------------------------------------------
cnCust.Close
Set cnCust = Nothing
'------------------------------------------------------------------------------
'--- All ASP post processing code goes here, as well as
'--- sub routines and functions
'------------------------------------------------------------------------------
%>
I'm going to go to a third page as well, but i need to get the ID passed before i can continue. Thanks