tags:

views:

244

answers:

1

I am new to VBscript, so I need help with the following. As you notice on line 12, vercode is mentioned. I want a statement there saying that if vercode is not "1234" nothing else will help (ie scripts terminate). Do you know how?

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!-- #INCLUDE file="inc/settings.asp" -->
<!-- #INCLUDE file="inc/functions.asp" -->
<!-- #INCLUDE file="inc/db_connect.asp" -->
<%
nameSurname = sqlquote(trim(request.form("name"))) & ""
comment = sqlquote(trim(request.form("comment")) & "")
nid = request.form("nid")
pid = request.form("pid")
comment_date = DatePart("d",now()) & "/" & DatePart("m",now()) & "/" & DatePart("yyyy",now())

if vercode = "1234" then
if nameSurname = "" then nameSurname = "Anonymous" end if
if comment <> "" then 
    strSQL = "INSERT INTO Comments (fName, Comment, DateSubmitted, NewsID) " &_
              "VALUES ('" & nameSurname & "', '" & comment & "', #" & comment_date & "#, " & nid & ");"
    con.execute strSQL
    con.close
end if
response.redirect("news.asp?NewsID=" & encrypt(nid) & "&PID=" & encrypt(pid) )
%>
A: 

How about instead of terminating the script if vercode is not "1234", you run the interesting part of your script if it is equal to "1234", like below:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="65001"%>
<!-- #INCLUDE file="inc/settings.asp" -->
<!-- #INCLUDE file="inc/functions.asp" -->
<!-- #INCLUDE file="inc/db_connect.asp" -->
<%
nameSurname = sqlquote(trim(request.form("name"))) & ""
comment = sqlquote(trim(request.form("comment")) & "")
nid = request.form("nid")
pid = request.form("pid")
comment_date = DatePart("d",now()) & "/" & DatePart("m",now()) & "/" & DatePart("yyyy",now())

if vercode = "1234" then
  if nameSurname = "" then 
    nameSurname = "Anonymous" 
  end if
  if comment <> "" then 
    strSQL = "INSERT INTO Comments (fName, Comment, DateSubmitted, NewsID) " &_
                                        "VALUES ('" & nameSurname & "', '" & comment & "', #" & comment_date & "#, " & nid & ");"
                                        'debugging strsql
    con.execute strSQL
    con.close
  end if
  response.redirect("news.asp?NewsID=" & encrypt(nid) & "&PID=" & encrypt(pid) )
end if    
%>
Jay Riggs
it did not work :/ somehow
I HAVE UPDATE THE WORDING AS JAY RIGGS HAS TOLD ME...... it still doesnt work. please help. 10x
I've updated my response based on some changes you made. Try it out and if it doesn't work try to describe the problem
Jay Riggs