Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I want to insert with form textarea input html with asp code to acces 2000 database.

This is ok, but when retrieve the recordset from an asp page the part of asp code is just text. What im doing wrong.

What I have tried:

The Insert Code:
HTML
<%
    Set MM_editCmd = Server.CreateObject ("ADODB.Command")
    MM_editCmd.ActiveConnection = MM_conn_STRING
    MM_editCmd.CommandText = "INSERT INTO KioskLayout (KioskHtml) VALUES (?)" 
    MM_editCmd.Prepared = true

    MM_editCmd.Parameters.Append MM_editCmd.CreateParameter("param5", 203, 1, 536870910, Request.Form("KioskLayHtml")) ' adLongVarWChar
    MM_editCmd.Execute
    MM_editCmd.ActiveConnection.Close
%>


The Html Form Code:
HTML
<form METHOD="POST" name="Layout" action="<%=MM_editAction%>" class="center">
  <textarea class="form-control" id="KioskLayHtml" name="KioskLayHtml">
<!--This is The TextArea field Input --> 
  <div class="grid-container">
<div class="main"><%=rs("today")%></div>
<div class="Left"><%=rs("tomorrow")%></div>
<div class="Bottom"><%=rs("yesterday")%></div>
</div>
<!--End Of TextArea field Input --> 
  </textarea>
<input type="hidden" name="MM_insert" value="Layout">
<input type="submit" name="button" id="button" value="Submit">
</form>


But when retrieve the recordset from an asp page shows this.

<%=rs("today")%>
<%=rs("tomorrow")%>
<%=rs(yesterday")%>

as text,
and view the source shows this.

 <div class="grid-container">
<div class="main"><%=rs("today")%></div>
<div class="Left"><%=rs("tomorrow")%></div>
<div class="Bottom"><%=rs("yesterday")%></div>
</div>


Any help? Thanks in advance
Posted
Updated 8-Mar-20 0:35am
Comments
Richard Deeming 6-Mar-20 7:22am    
It sounds like your "HTML form" code is in an HTML page, rather than an ASP page.
Member 13741482 6-Mar-20 10:43am    
No, my page is .asp
The contents of request.form("KioskLayHtml") is html and asp code.
MadMyche 6-Mar-20 7:24am    
How does the Form Action render; is it messed up as well or did it render properly? Is this page actually saved with the ASP extension? Has it worked previouly? Do you have functioning ASP pages on the site? And are you actually using DreamWeaver?
Member 13741482 6-Mar-20 10:46am    
The insert form works fine. yes, it is an asp page on local iis on windows 7 and yes i'm using Dreamweaver 4.0
Richard Deeming 6-Mar-20 7:25am    
Or is that HTML form code loaded from a database? If you write out the value of a database field, ASP code embedded within that database value won't be executed.

1 solution

When writing out the stored asp code from the database, you need to execute it rather than just copy the "source", which as far as ASP knows, is just some text.
There is a way to do this: use the eval() function. See VBScript Eval function[^]

Whilst this may resolve your problem, it is (a) very inefficient, and (b) very dangerous - in terms of security. If you don't have control over that database-stored ASP code, it could be doing virtually anything on your server. Unless this is a tightly-pinned down application with access control, I would advise against it and rethink your application design.
 
Share this answer
 
Comments
Member 13741482 8-Mar-20 7:55am    
i tried but i cannot make happend. My variable is <%=rs("KioskHtml")%> where inside holds
the database value



<%=rs("today")%>
<%=rs("tomorrow")%>
<%=rs("yesterday")%>


with this code

```
<%
Var1 = (Rs("KioskHtml"))

response.write(Eval("Var1"))
%>
```
the result are the same, Just text.
Thank you for replying! Appreciate it.
DerekT-P 8-Mar-20 15:33pm    
So you need to be evaluating CODE, not text. If the text contains things like <% then that's not VBScript code so can't be evaluated in any way other than text. <% is just a context switch between HTML and VBScript. Also in your Eval statement you've enclosed the variable name in quotes, so evaluating a text string will just return text.
Change the text in the database:
Response.Write rs("today")
Response.Write rs("tomorrow")
Response.Write rs("yesterday")

Then you can do something like
<%
var1=rs("KioskHtml")
Response.Write Eval(var1)
%>
Now, because you're evaluating VBScript, if you need to emit HTML you can't just embed it, or context switch from VBScript to HTML; you need to write VBScript that will emit it. So for instance if you want those three values on separate lines, change the database value to (for example):
Response.Write rs("today") & ""
Response.Write rs("tomorrow") & ""
Response.Write rs("yesterday") & ""
If you're not entirely comfortable with the concept, just knock up a simple test page and experiment until you've really grasped what you're doing.
DerekT-P 8-Mar-20 15:36pm    
haha... the editor has lost the [br /] code in those last few lines; so it should be
Response.Write rs("today") & "[br /]"
Response.Write rs("tomorrow") & "[br /]"
Response.Write rs("yesterday") & "[br /]"
... but of course change those square brackets for angle brackets. Sorry if that's confused things!
Member 13741482 11-Mar-20 8:14am    
If understand you mention, because is mixed, html with <%%> code, there is no solution, im right?
Editor somehow had delete some code from my example.

On my first post can you see all the textarea code, and is mixed.

And this is what i want to insert in database as one value.
Thank you for your time, And Have a Nice Life
DerekT-P 11-Mar-20 8:50am    
Well thank you for the good wishes! If the code on the database is mixed, but has only <% %> tags, then simply remove them before evaluating (e.g. eval(replace(replace(var1,"<%=",""),"%>","")). If there's other HTML in there between the tags, it's a bit more complex and you'd need to use something like RegEx to split out the ASP code from HTML and then loop through the parts, either emitting them unchanged (the HTML bits) or emitting the EVALuated bits of code. A bit trickier but do-able.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900