×

Loading...
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务
Ad by
  • 推荐 OXIO 加拿大高速网络,最低月费仅$40. 使用推荐码 RCR37MB 可获得一个月的免费服务

a problem in my ASPcode. Thanks.

i want to use following code to insert data into database:
-------------------------------------
<script language="vbscript">
newusername=<%=session("newusername")%>
</script>
<%
if newusername<>"" then
sqlstring=" INSERT INTO result (username,col1,col2,col3,col4)VALUES(' '"&newusername&"',1,2,3,4)"
Con.Execute sqlstring
end if
%>
the session variable is defined properly, and can be read by other code directly in this page,ie, if i code : document.write "my name is <%=session("newusername")%>",it can display properly.
But when I intend to insert it into databse by assigning the session variable to another variable, it doesn't work. Could you tell me why and how to fix it? thanks a lot.
Report

Replies, comments and Discussions:

  • 工作学习 / IT技术讨论 / a problem in my ASPcode. Thanks.
    i want to use following code to insert data into database:
    -------------------------------------
    <script language="vbscript">
    newusername=<%=session("newusername")%>
    </script>
    <%
    if newusername<>"" then
    sqlstring=" INSERT INTO result (username,col1,col2,col3,col4)VALUES(' '"&newusername&"',1,2,3,4)"
    Con.Execute sqlstring
    end if
    %>
    the session variable is defined properly, and can be read by other code directly in this page,ie, if i code : document.write "my name is <%=session("newusername")%>",it can display properly.
    But when I intend to insert it into databse by assigning the session variable to another variable, it doesn't work. Could you tell me why and how to fix it? thanks a lot.
    • <script language="vbscript">
      newusername=<%=session("newusername")%>
      </script>

      上面这段不用这么费劲的,这样

      <script language="vbscript">
      newusername=session("newusername")
      </script>

      或者简单的这样

      <%
      newusername=session("newusername")
      %>

      就可以了
      • Thanks. I'll tell u what happens later, I need sleep now.Good Night.
    • 把读session的那句话换成 newusername=session("newusername") 试试
    • 你定义的newusername是VBscript里的变量,用的时候在ASP里用,当然不行了
      在服务器端,ASP和Script代码按顺序执行。但ASP是没办法读到Script的变量的。你可以把变量直接在ASP代码里定义,或者放到一个Hidden里去
      • According to my knowledge,ASP is actually a mixture of vbscript and sql etc.So your explaination is not right. I have solve the problem with the advice from Rootbear abd Booker. Thank you all.
        • ASP is mixture of vbscript and sql huh..?? The best joke I heard today.
      • You are asoblutely right, though it is not my problem.