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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Pulling ASP code from a database field

Status
Not open for further replies.
Feb 20, 2001
24
US
Let me explain my situation. I have a page which has several sections on it. For the most part the content in these sections is going to stay the same on a day to day basis. However occasionally the content is going to change based on the date. So, for example on Valentine's Day, there might be an announcement about a special sale for that day only. My original idea was to store the contents of each section in a database. There would be default rows which would show up, unless there was a row for that specific date. This looked like it would work fine, until I realized that there was going to be ASP code within the data.

So for example I'd have something like this in my database:

<a href="/sales.asp?CartID=<%=CartID%>">Today's Specials</a>

When this data was pulled the ASP Code was not being executed. After doing some research, it appears to me as if there is not a way to have code pulled from a database executed. My question is, am I correct in this assessment? Is there no way to store code in a database and have it executed once it is pulled? And if not, does anyone have any better ideas on how to do what I want to do? Thanks in advance and please let me know if you need more information or clarification, or if there is a better forum for this question.
 
I havn't a lot of time so yes there is a way to do that. Hope this gets you started

sql = "SELECT * FROM [Sales] WHERE [Sales].[CartID]=" & Request.QueryString("ID")
rs.open sql, conn, 3, 3

session("id")=rs("CartID")
session("sales_item")=rs("SalesItem")
rs.close
Conn.Close

Response.Redirect "/sales/salesitem/"
Response.End
 
Oh use single quotes like so

<a target='_blank' href='/processing.asp?ID=" & rs("ID") & "'>
 
<%
<a target='_blank' href='/processing.asp?ID=" & rs("DebtorID") & "'>
%>

Sorry in a rush hope this helps
 
You can execute code from a string (regardless of the source, e.g. database, file, etc), using the Execute() function.


You need to be very careful about using this though, as it can introduce bugs and issues that make your coding messy and unruly. It may also make your design harder to work with, and depending on how the source data gets added/edited/etc, it may introduce serious security issues.

Again, it depends on your design, but you may want to create a simple parser for the text, which replaces keywords with values, or make the content returned more fine grained so you only return the change in text, and use logic in the page where the ASP is needed currently.

You may be able to eliminate the asp code requirement completely from the data source if you make a few design changes. The example you included above doesn't make sense, as it seems to indicate that the link "Todays specials" goes to the users cart... ? a) why not use a session variable for the cart id, and b) why would a user want to go to their cart when looking for todays specials ? it may just be an example, but you get my point.



A smile is worth a thousand kind words. So smile, it's easy! :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top