ASP Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsProgramming Languages - MoreASP Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old May 16th, 2012, 04:31 AM
craigward craigward is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2007
Posts: 62 craigward User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 17 h 56 m 34 sec
Reputation Power: 6
Question Linking ASP to stored procedure

Hi There,

I have written an ASP page that links with an SQL database. A user can enter a value in a single field and search the database, when results are found they are returned in the asp code.

The code all works fine and does what i need but i am concerned that having the SQL in the same page as the ASP might be a little un-safe. I was wondering what would be the best method to hide the SQL code from the ASP page, maybe an include file? or better still a stored procedure.

Does anyone have an idea how i could integrate a stored procedure into my code below, i've looked but never havign done one before it's not that straight forward.

Many thanks for looking.

The SQL and entire ASP code is below.

SQL CODE:

Code:
<!--#include file="include/connection.asp"-->
<%
search = ""
search = Request.QueryString("search")
SearchCriteria = Request.Form("directorysearch")
If Len(SearchCriteria) > 2 Then
    qry_count = "SELECT count(*) as count FROM wce_contact where ((company like '%"&SearchCriteria&"%' OR type_of_business like '%"&SearchCriteria&"%' OR Business_Overview like '%"&SearchCriteria&"%' OR services like '%"&SearchCriteria&"%') AND (General_Public_Facing = 'y'))"

    Set oRs_count = connStr.Execute(qry_count)
    count = (oRs_count("count"))

    qry = "SELECT * FROM wce_contact WHERE((General_Public_Facing = 'y') AND (company LIKE '%"&SearchCriteria&"%' OR type_of_business LIKE '%"&SearchCriteria&"%' OR Business_Overview LIKE '%"&SearchCriteria&"%' OR services LIKE '%"&SearchCriteria&"%'))"
    Set oRs = connStr.Execute(qry)
Else
    search = ""
End If
%>




Entire Code:

Code:
<!--#include file="include/connection.asp"-->
<%
search = ""
search = Request.QueryString("search")
SearchCriteria = Request.Form("directorysearch")
qry_count = "SELECT count(*) as count FROM wce_contact where ((company like '%"&SearchCriteria&"%' OR type_of_business like '%"&SearchCriteria&"%' OR Business_Overview like '%"&SearchCriteria&"%' OR services like '%"&SearchCriteria&"%') AND (General_Public_Facing = 'y'))"

Set oRs_count = connStr.Execute(qry_count)

count = (oRs_count("count"))

'response.write(count)
'response.end

qry = "SELECT * FROM wce_contact WHERE((General_Public_Facing = 'y') AND (company LIKE '%"&SearchCriteria&"%' OR type_of_business LIKE '%"&SearchCriteria&"%' OR Business_Overview LIKE '%"&SearchCriteria&"%' OR services LIKE '%"&SearchCriteria&"%'))"

'response.write(qry)

Set oRs = connStr.Execute(qry)

'business_name =  (oRs("company"))

'response.write(lup)
'response.end

%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title> Portal</title>
<link type="text/css" href="portal/css/stylesheet.css" rel="stylesheet">

<script language="">
function checkfield(){
	if(document.forms[0].directorysearch.value == ""){
		alert("Please enter a search value");
	}
	else {
	
	document.forms[0].submit();
	}
}

</script>
</head>
<form name="DirectorySearch" method="post" action="DirectorySearch.asp?search=yes">
<body>
	<table border=0>
		<tr><td colspan=2>&nbsp;</td></tr>
		<tr><td class=lbl align=right colspan=2>Search directory &nbsp; <input type=text name="directorysearch"> &nbsp; <input type="button" onclick="checkfield()" value="Click to Search"></td></tr>
		<tr><td colspan=2>&nbsp;</td></tr>
<% If (search <> "") Then %>
	 
	<% If (oRs_count("count")) => "1" Then %>
	
	
	<% Do while not oRs.eof %>

		<tr><td class=lbl>Business Name</td>
			<td class=Text> <% response.write(oRs("company")) %></td></tr>	
	
	<% If (oRs("Name_Enfield_Business_Directory")) = "y" Then %> <tr><td class=lbl>Salutation</td>
			<td class=Text> <% response.write(oRs("Salutation")) %></td></tr> <% Else %> <% End If %>		
	<% If (oRs("Name_Enfield_Business_Directory")) = "y" Then %> <tr><td class=lbl>First Name</td>
			<td class=Text> <% response.write(oRs("firstname")) %></td></tr> <% Else %> <% End If %>	
	<% If (oRs("Name_Enfield_Business_Directory")) = "y" Then %> <tr><td class=lbl>Last Name</td>
			<td class=Text> <% response.write(oRs("lastname")) %></td></tr> <% Else %> <% End If %>	
			

	<% If (oRs("address_Enfield_Business_Directory")) = "y" Then %> <tr><td class=lbl>Address</td>
			<td class=Text> <% response.write(oRs("Building_Name_Flat_Number")) %>, <% response.write(oRs("unit_number")) %>, <% response.write(oRs("Estate_or_Business_Centre")) %>, <% response.write(oRs("address1")) %>,  <% response.write(oRs("address2")) %>, <% response.write(oRs("city")) %>, <% response.write(oRs("county")) %>, <% response.write(oRs("postalcode")) %></td></tr> <% Else %> <% End If %>	

	<% If (oRs("mobile_Enfield_Business_Directory")) = "y" Then %> <tr><td class=lbl>Mobilephone</td>
			<td class=Text> <% response.write(oRs("mobilephone")) %></td></tr> <% Else %> <% End If %>	
			
		<tr><td class=lbl>Telephone</td>
			<td class=Text><% response.write(oRs("phone")) %></td></tr>
		<tr><td class=lbl>08 numbers</td>
			<td class=Text><% response.write(oRs("Zero_Eight_Numbers")) %></td></tr>
		<tr><td class=lbl>Type of Business</td>
			<td class=Text><% response.write(oRs("type_of_business")) %></td></tr>
		<tr><td class=lbl>Generic Email</td>
			<td class=Text><% response.write(oRs("Generic_Email")) %></td></tr>
		<tr><td class=lbl>Website</td>
			<td class=Text> <% response.write(oRs("website")) %></td></tr>
		<tr><td class=lbl>Business Overview</td>
			<td class=Text><% response.write(oRs("Business_Overview")) %> </td></tr>
		<tr><td class=lbl>Services</td>
			<td class=Text><% response.write(oRs("services")) %> </td></tr>
		<tr><td colspan=2>&nbsp;</td></tr>
		<tr><td colspan=2><hr></td></tr>
	<% 
	oRs.movenext 
	Loop
	
	oRs.Close
	Else
	lup = ""
	SearchCriteria = ""
	oRs.Close
	End If
	
	lup = ""
	SearchCriteria = ""
	'End If
	
Else

End If	
	%>
	</table>
	</form>
</body>

</html>


Reply With Quote
  #2  
Old May 16th, 2012, 01:22 PM
Doug G Doug G is offline
Grumpier Old Moderator
Dev Shed God 19th Plane (14000 - 14499 posts)
 
Join Date: Jun 2003
Posts: 14,233 Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level)Doug G User rank is General 52nd Grade (Above 100000 Reputation Level) 
Time spent in forums: 1 Month 4 Weeks 14 h 15 m 56 sec
Reputation Power: 4445
One way is to use the sql EXEC statement, or you can use a command object.
__________________
======
Doug G
======
It is a truism of American politics that no man who can win an election deserves to. --Trevanian, from the novel Shibumi

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreASP Programming > Linking ASP to stored procedure

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap