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!

Search page not working!

Status
Not open for further replies.

tazzer

Technical User
May 3, 2001
11
0
0
GB
Hi,

I've created a search page that pulls name details from an Access database. Originally the search took the user to a results page that I created but I've been asked to incorporate the results into the search.asp page itself. My code is below, but it causes all the names in the database to appear automatically. How can I stop this?

Regards,

Tazzer

<HTML>
<HEAD>
<TITLE>INI Intranet : Directory Search</TITLE>
</HEAD>
<BODY bgColor=#e0e0e0>
<div align=&quot;center&quot;>
<p><IMG src=&quot;title.gif&quot;></p>


<font face=Verdana size=1 colour=&quot;73734d&quot;><b>To search for a staff member's phone number<br> enter the <font SIZE=2 color=&quot;red&quot;>first name</font>
into the first field and<br> the <font size=2 color=&quot;red&quot;>surname</font> into the second field, then<br> click on the <font SIZE=2 color=&quot;red&quot;>Search button.</font>
Alternatively,<br> you can enter either a first name or surname only,<br> or even just the first few letters of a name.</b></font>
</div>
<p> </p>
<table align=&quot;center&quot;>
<TBODY>
<tr>
<form name=&quot;frmInternalDirectory&quot; method=&quot;post&quot; action=&quot;search1.asp&quot;>
<td><input name=&quot;txtFirstName&quot; width=&quot;20&quot; ><input name=&quot;txtSurname&quot; width=&quot;20&quot; ></td>
<td align=&quot;middle&quot;><input type=&quot;submit&quot; value=&quot;Search&quot;></td>
</form>
</TBODY>
</table>
<table align=&quot;center&quot;><tr></tr><td>
<font face=Verdana size=1>For any queries or additions required to the directory contact HR Facilities Management<br>
at <a href=&quot;mailto:Valerie.Warwick; Patrick.Bogan@investi.com&quot;>Chichester Street</a>, <a href=&quot;mailto:Molly.Vannan@investi.com&quot;> Upper Galwally</a> or
<a href=&quot;mailto:Oliver.Corr@investi.com&quot;>Lisburn</a> or for technical problems contact the<br> <a href=&quot;mailto:helpdesk@investi.com&quot;>ICT eBusiness Internal team</a>.</font>
</td></tr>
</table>
</BODY>
</html>

<HTML>
<HEAD>
<TITLE>INI Intranet : Result</TITLE>
</HEAD>

<BODY bgcolor=#e0e0e0>
<%dim conn, rs
set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Open(&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Microsoft Site Server\Data\Publishing\ininet\TelDir\directory.mdb;Persist Security Info=False&quot;)
sql = &quot;SELECT * FROM tblInternalDirectory WHERE strFirstName LIKE '&quot;
sql = sql & Request.Form(&quot;txtFirstName&quot;) & &quot;%' AND&quot;
sql = sql & &quot; strLastName LIKE '&quot; & Request.Form(&quot;txtSurname&quot;) & &quot;%'&quot; & &quot;ORDER BY strLastName ASC&quot;
set rs = conn.execute(sql)
'if a non-existent recordset is entered this reply will be shown
if rs.BOF and rs.EOF then
Response.Write &quot;<font face=Verdana size=1><b>Sorry there is no data entered for this person. Please try again.</b></font>&quot;
else
'response.write sql
Response.Write &quot;<p>&quot;
Response.Write &quot;<p> &quot;
Response.Write &quot;<TABLE BORDER=0 BORDERCOLOUR=73734d align=center cellpadding=5>&quot;
Response.Write &quot;<TR>&quot;
Response.Write &quot;<td><b><font face=Verdana size=1>First Name</b></td>&quot;
Response.Write &quot;<td><b><font face=Verdana size=1>Surname</b></td>&quot;
Response.Write &quot;<td><b><font face=Verdana size=1>Department</b></td>&quot;
Response.Write &quot;<td><b><font face=Verdana size=1>Extension/ Speedial</b></td>&quot;
Response.Write &quot;<td><b><font face=Verdana size=1>Direct Line</b></td>&quot;
Response.Write &quot;<td><b><font face=Verdana size=1>Mobile</b></td>&quot;
Response.Write &quot;<td><b><font face=Verdana size=1>Location</b></td>&quot;
Response.Write &quot;</tr>&quot;
Do until rs.EOF
response.write &quot;<TR>&quot;
response.write &quot;<TD><font face=Verdana size=1 color=red>&quot; & rs(&quot;strFirstName&quot;) & &quot;</TD>&quot;
response.write &quot;<TD><font face=Verdana size=1 color=red>&quot; & rs(&quot;strLastName&quot;) & &quot;</TD>&quot;
response.write &quot;<TD><font face=Verdana size=1>&quot; & rs(&quot;strDepartment&quot;) & &quot;</TD>&quot;
response.write &quot;<TD><font face=Verdana size=1>&quot; & rs(&quot;intExtension&quot;) & &quot;</TD>&quot;
response.write &quot;<TD><font face=Verdana size=1>&quot; & rs(&quot;intDirect&quot;) & &quot;</TD>&quot;
response.write &quot;<TD><font face=Verdana size=1>&quot; & rs(&quot;intMobile&quot;) & &quot;</TD>&quot;
response.write &quot;<TD><font face=Verdana size=1>&quot; & rs(&quot;strRegion&quot;) & &quot;</TD>&quot;
response.write &quot;</TR></font>&quot;
rs.movenext
Loop
response.write &quot;</TABLE>&quot;
end if
rs.close
conn.close
set rs = nothing
set conn = nothing
%>
</BODY>
</HTML>
 
The code you've posted looks like the two individual pages you had originally. Can you post your single search and display code?
 
You can use something like the Request.TotalBytes
This will be 0 if you did not submit a form

If the results have to be displayed in the search.asp why is the action for the form search1.asp??
I changed the action of the code below to search.asp, this should work fine.


<%response.expires = -1 ' page will be refreshed every time
if Request.TotalBytes = 0 then
%>
<HTML>
<HEAD>
<TITLE>INI Intranet : Directory Search</TITLE>
</HEAD>
<BODY bgColor=#e0e0e0>
<div align=&quot;center&quot;>
<p><IMG src=&quot;title.gif&quot;></p>


<font face=Verdana size=1 colour=&quot;73734d&quot;><b>To search for a staff member's phone number<br> enter the <font SIZE=2 color=&quot;red&quot;>first name</font>
into the first field and<br> the <font size=2 color=&quot;red&quot;>surname</font> into the second field, then<br> click on the <font SIZE=2 color=&quot;red&quot;>Search button.</font>
Alternatively,<br> you can enter either a first name or surname only,<br> or even just the first few letters of a name.</b></font>
</div>
<p> </p>
<table align=&quot;center&quot;>
<TBODY>
<tr>
<form name=&quot;frmInternalDirectory&quot; method=&quot;post&quot; action=&quot;search.asp&quot;>
<td><input name=&quot;txtFirstName&quot; width=&quot;20&quot; ><input name=&quot;txtSurname&quot; width=&quot;20&quot; ></td>
<td align=&quot;middle&quot;><input type=&quot;submit&quot; value=&quot;Search&quot;></td>
</form>
</TBODY>
</table>
<table align=&quot;center&quot;><tr></tr><td>
<font face=Verdana size=1>For any queries or additions required to the directory contact HR Facilities Management<br>
at <a href=&quot;mailto:Valerie.Warwick; Patrick.Bogan@investi.com&quot;>Chichester Street</a>, <a href=&quot;mailto:Molly.Vannan@investi.com&quot;> Upper Galwally</a> or
<a href=&quot;mailto:Oliver.Corr@investi.com&quot;>Lisburn</a> or for technical problems contact the<br> <a href=&quot;mailto:helpdesk@investi.com&quot;>ICT eBusiness Internal team</a>.</font>
</td></tr>
</table>
</BODY>
</html>

<%else
%>


<HTML>
<HEAD>
<TITLE>INI Intranet : Result</TITLE>
</HEAD>

<BODY bgcolor=#e0e0e0>
<%dim conn, rs
set conn = Server.CreateObject(&quot;ADODB.Connection&quot;)
conn.Open(&quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Microsoft Site Server\Data\Publishing\ininet\TelDir\directory.mdb;Persist Security Info=False&quot;)
sql = &quot;SELECT * FROM tblInternalDirectory WHERE strFirstName LIKE '&quot;
sql = sql & Request.Form(&quot;txtFirstName&quot;) & &quot;%' AND&quot;
sql = sql & &quot; strLastName LIKE '&quot; & Request.Form(&quot;txtSurname&quot;) & &quot;%'&quot; & &quot;ORDER BY strLastName ASC&quot;
set rs = conn.execute(sql)
'if a non-existent recordset is entered this reply will be shown
if rs.BOF and rs.EOF then
Response.Write &quot;<font face=Verdana size=1><b>Sorry there is no data entered for this person. Please try again.</b></font>&quot;
else
'response.write sql
Response.Write &quot;<p>&quot;
Response.Write &quot;<p> &quot;
Response.Write &quot;<TABLE BORDER=0 BORDERCOLOUR=73734d align=center cellpadding=5>&quot;
Response.Write &quot;<TR>&quot;
Response.Write &quot;<td><b><font face=Verdana size=1>First Name</b></td>&quot;
Response.Write &quot;<td><b><font face=Verdana size=1>Surname</b></td>&quot;
Response.Write &quot;<td><b><font face=Verdana size=1>Department</b></td>&quot;
Response.Write &quot;<td><b><font face=Verdana size=1>Extension/ Speedial</b></td>&quot;
Response.Write &quot;<td><b><font face=Verdana size=1>Direct Line</b></td>&quot;
Response.Write &quot;<td><b><font face=Verdana size=1>Mobile</b></td>&quot;
Response.Write &quot;<td><b><font face=Verdana size=1>Location</b></td>&quot;
Response.Write &quot;</tr>&quot;
Do until rs.EOF
response.write &quot;<TR>&quot;
response.write &quot;<TD><font face=Verdana size=1 color=red>&quot; & rs(&quot;strFirstName&quot;) & &quot;</TD>&quot;
response.write &quot;<TD><font face=Verdana size=1 color=red>&quot; & rs(&quot;strLastName&quot;) & &quot;</TD>&quot;
response.write &quot;<TD><font face=Verdana size=1>&quot; & rs(&quot;strDepartment&quot;) & &quot;</TD>&quot;
response.write &quot;<TD><font face=Verdana size=1>&quot; & rs(&quot;intExtension&quot;) & &quot;</TD>&quot;
response.write &quot;<TD><font face=Verdana size=1>&quot; & rs(&quot;intDirect&quot;) & &quot;</TD>&quot;
response.write &quot;<TD><font face=Verdana size=1>&quot; & rs(&quot;intMobile&quot;) & &quot;</TD>&quot;
response.write &quot;<TD><font face=Verdana size=1>&quot; & rs(&quot;strRegion&quot;) & &quot;</TD>&quot;
response.write &quot;</TR></font>&quot;
rs.movenext
Loop
response.write &quot;</TABLE>&quot;
end if
rs.close
conn.close
set rs = nothing
set conn = nothing
%>
</BODY>
</HTML>
<%end if%>
 
Hi tazzer

I'm new to asp but I managed to accomplish this using FP2000 - I'll try to explain what I did - but you'll have to write your own code!

Top of my page I have a database results region which is based on a WHERE statement looking for a variable name that matches the name of a drop-down OPTION box in a form I have further down the page.

fp_sQry=&quot;SELECT * FROM all_names WHERE (name_id = ::chosen_name_id::)&quot;

name_id is in the database, chosen_name_id refers to the form field name.

When the page is opened there are no results displayed (no submission from the form yet!). My &quot;no results&quot; text prompts the user to select from the drop-down box below.

Below the database results region there is the form which contains a drop-down OPTION box - also populated from the database (this prevents anyone searching for a non-existant name). ON SUBMIT points to the same asp page, so the page is re-loaded, but this time the variable in the WHERE clause has a value, and the results are displayed accordingly.

NOTE - I have also used a session variable to remember the selected option in the drop-down box so that when the page is refreshed the right name is still selected. - here is the code for that:

in the HTML tag:

<%
If Request.Form (&quot;chosen_name_id&quot;) > 0 Then Session (&quot;s_name_id&quot;) = Request.Form (&quot;chosen_name_id&quot;) End if
%>

Hence, if the form has been submitted, the variable &quot;chosen_name_id&quot; has a value, and it is recorded in the session variable &quot;s_name_id&quot;

and in the code for the drop-down OPTION box (please excuse the FrontPage syntax!):

<option VALUE=&quot;<%=FP_FieldHTML(fp_rs,&quot;chosen_name_id&quot;)%>&quot; <%If (FP_FieldHTML(fp_rs,&quot;chosen_name_id&quot;) = Session (&quot;s_name_id&quot;)) Then response.write &quot; selected &quot;%>><%=FP_FieldHTML(fp_rs,&quot;Name&quot;)%></option>

I acually have four drop-down boxes in the form, and it works like a charm. As I said, I didn't write the code myself (apart from the session variable stuff), FrontPage did, so posting it all here would be a mess! However, hope I was able to help!

Pete
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top