Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - ASP Searching Code Help
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

ASP Searching Code Help

 Post Reply Post Reply
Author
ainsworth14 View Drop Down
Groupie
Groupie


Joined: 05 August 2003
Location: United Kingdom
Status: Offline
Points: 62
Post Options Post Options   Thanks (0) Thanks(0)   Quote ainsworth14 Quote  Post ReplyReply Direct Link To This Post Topic: ASP Searching Code Help
    Posted: 21 August 2003 at 11:31am

Hi all,

having got very limited knowledge (ie: None) of ASP code, I have found the below code on the net for searching my access DB from an asp page, could someone please help me and highlight the actual bits of code i need to change to peronalise to my own DB, i have had a bash myself but iall i get when i preview the site is a n error stating 'that a virtual path must be used, a pshyical was stated'???

....any help greatly appreciated.

<%
u_input = trim(request.form("u_input")) 'u_input is the varible for user input 
' the trim function removes any blanks around the the use input
u_field=request.form("u_field") 'the dropdown varible for user inputted search field

if u_input <> "" then ' If the user entered a value query the db
accessdb="state_info" ' name of the access db 
table_name="states" ' name of the table within the access db
cn="driver={microsoft access driver (*.mdb)};"
cn=cn & "dbq=" & server.mappath(accessdb)
set rs = server.createobject("ADODB.Recordset")
sql = "select * from "& table_name &" where " & u_field & " like '%%" & u_input & "%%' " 
response.write sql
rs.Open sql, cn

if rs.eof or rs.bof then 
response.write "No results found..." 
observations=0
else
observations=1
end if 'end check for observations
end if 'end check for user input
%>
<% 'If there are observations then display them 
if observations > 0 then %>
<table>
<tr>
<% 'Write the field names
for each table_element in rs.fields %>

<td><b><%= table_element.name%></B></TD><%
next %>

</tr>
<tr>
<% 'Write the values
rs.movefirst
do while not rs.eof
for each cell in rs.fields %>

<td><%= cell.value %></td><% 
next %>

</tr>
<% rs.movenext
loop %>

</table>
<% end if 'end of check of obs for display %>


<form action ="<%= request.servervariables("script_name") %>" method="post">
<input type="text" name="u_input" value="<%= u_input %>">
<select name="u_field" size="1">
<option <% ' write out all the search fields and select
if u_field = "state" or u_field = "" then
response.write "selected "
end if
%>
value="state">State</option>
<option <%
if u_field = "statename" then
response.write "selected "
end if
%>
value="statename">State Name</option>
<option <%
if u_field = "capital" then
response.write "selected "
end if
%
>value="capital">Capital</option>
</select>
<input type="submit" value="Submit">
</form>

Back to Top
pmormr View Drop Down
Senior Member
Senior Member


Joined: 06 January 2003
Location: United States
Status: Offline
Points: 1479
Post Options Post Options   Thanks (0) Thanks(0)   Quote pmormr Quote  Post ReplyReply Direct Link To This Post Posted: 27 August 2003 at 6:45pm
the dbq at the top is using server.mappath. Server.mappath returns the physical path to the file. try replacing that line with the virtual path to your database. I.e. /myfolder/mydatabase.mdb
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.