I've got 20 pages that all have an identical code block that opens a db and assigns recordset to variables. Only difference is the product_id used in the query. I want to move this code to an include, and just call it on each page.
If I put the function on the actual page it works, but once I put it in the include I'm getting the error: Variable is undefined: 'prod_query'
I've tried doing it as both a sub and a function, but get the same error.
the include that defines the prod_query function is called before I try to use it. Any clues what I'm doing wrong? I'm not trying to return a value from the function, just using it to define variables I use later on the page.
<%@ Language=VBScript %>
<% OPTION EXPLICIT %>
<!--#include file="shop$db.asp"-->
<!--#include file="INC_prod_query.asp"-->
<%
Dim product_id
product_id = 69
Dim dbc, rs
shopopendatabaseP dbc
prod_query(product_id) ' call function in INC_prod_query.asp
%>
Here is the include file:
dim query, prod_name, prod_description, prod_extendeddesc, prod_ingredients, prod_price, prod_image, prod_weight
function prod_query(id)
query = "select cname, cdescription, extendeddesc, ingredients, pother1, cprice, cimageurl from products where catalogid = " & product_id
set rs = dbc.execute(query)
If not rs.EOF Then
prod_name = rs("cname")
prod_description = rs("cdescription")
prod_extendeddesc = rs("extendeddesc")
prod_ingredients = rs("ingredients")
prod_price = rs("cprice")
prod_image = rs("cimageurl")
prod_weight = rs("pother1")
end if
set rs=nothing
exit sub
end function