PDA

View Full Version : Anyone please help with asp


ianhull
06-12-2005, 02:28 PM
Can anyone please help me with this asp sample?
I know that many of you are into php but I recall one of you helping me with asp before.

I have a selection box where I can choose country, after I select the country a table is created with 3 columns from the database

I then want to post the record from column 1 to a processform.asp "which works fine" this column is called companyname.

Here is what I have

<html>
<body>

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open(Server.Mappath("/db/northwind.mdb"))

set rs=Server.CreateObject("ADODB.recordset")
sql="SELECT DISTINCT Country FROM Customers ORDER BY Country"
rs.Open sql,conn

country=request.form("country")

%>

<form method="post">
Choose Country <select name="country">
<% do until rs.EOF
response.write("<option")
if rs.fields("country")=country then
response.write(" selected")
end if
response.write(">")
response.write(rs.fields("Country"))
rs.MoveNext
loop
rs.Close
set rs=Nothing %>
</select>
<input type="submit" value="Show customers">
</form>

<%
if country<>"" then
sql="SELECT Companyname,Contactname,Country FROM Customers WHERE country='" & country & "'"
set rs=Server.CreateObject("ADODB.Recordset")
rs.Open sql,conn
%>
<table width="100%" cellspacing="0" cellpadding="2" border="1">
<tr>
<th>Companyname</th>
<th>Contactname</th>
<th>Country</th>
</tr>
<%
do until rs.EOF
response.write("<tr>")
response.write("<td>" & rs.fields("companyname") & "</td>") \\I want to post this to the next page
response.write("<td>" & rs.fields("contactname") & "</td>")
response.write("<td>" & rs.fields("country") & "</td>")
response.write("</tr>")
rs.MoveNext
loop
rs.close
conn.Close
set rs=Nothing
set conn=Nothing%>
</table>
<% end if %>

</body>
</html>

If anyone can help with this it will be very much appreciated.

Thanks Guys.

Philo
06-13-2005, 03:12 AM
Im a little bit confused as to what you want to do so may have the worng end of the stick.

If you want to send the value from this page to the next you could include it inside your form.

<input type="text" value="<%=rs.fields("companyname")%>">

You could also do

<input type="hidden" value="<%=rs.fields("companyname")%>">

If you wanted to pass a value but not display it to the user.

Philo
06-13-2005, 04:04 AM
sorry that should be:

<input type="text" name="a_name" value="<%=rs.fields("companyname")%>">

ianhull
06-13-2005, 05:26 AM
Thanks Philo,

It does not sem to work but I will keep trying, I appreciate your help.

:yes

Philo
06-14-2005, 02:46 AM
Ensure that line is within your form tags

Alternatively

Have you tried session variables?

Try Session("companyname") = rs.fields("companyname")

Then you can return it on any future pages by doing

Dim companyname
companyname = Session("companyname")

Have a look here for more info
http://www.w3schools.com/asp/asp_sessions.asp