theunknownknight
MIS
Below is a snippet of code I am working on in a relatively simple project. I have a form that request 2 fields. In the vbscript I validate whether or not it exist and so on. My problem comes in when I try and add the data to the recordset. This prog simply adds IDs and Passwords to a rec set. It is not working. I initiate valid to false. In the function Validate() in it is changed to true. But for some reason, it isn't adding. I am new to this and would appreciate any help. Thanks.
<%@ Language = "VBScript"%>
<%
Public Valid
valid = false
%>
<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<TITLE>AIR</TITLE>
<SCRIPT LANGUAGE=VBscript>
<!--option explicit
function Validate()
dim Logon
dim Flag
valid = false
Flag = false
Logon = document.AIR1.txtLogonID.value
Password = document.AIR1.txtPassword.value
if Logon = "" then
msgbox "Enter in Your Logon ID",,"No Logon ID"
else
if Isnumeric(Logon) then
msgbox "There must me alpha characters in your Logon ID",,"Invalid Data"
else
if password = "" then
msgbox "No Password was Entered",,"Need Password"
else
flag = true
valid = true
end if
end if
end if
end function
-->
</SCRIPT>
</HEAD>
<BODY bgColor=silver>
<FORM METHOD="post" NAME="AIR1">
<p> </p>
<strong><u>AIR</u></strong>
<P>
Logon ID: <INPUT NAME="LogonID" id=txtLogonID><br>
Password: <INPUT NAME="Password" id=txtPassword> </P>
<P id=frmAIR> <br> </P>
<input id =cmdSubmit type=submit value=submit name=button1 onclick = validate()>
</FORM>
<%
if valid = true then
'Declaring variables
'Opening and connecting to data
dim conn
dim rs
dim strID
dim strconn
'set a local variable to my DSN-less connection String
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("TPL.mdb"
'Create the Connection object
set conn = server.createobject("adodb.connection"
conn.open strconn
'Create the recordset object
set rs = server.createobject("adodb.recordset"
'This statement opens the table so we can add a record notice the addnew
'The 2, 2 is how the table is opened there are many ways it can be opened
rs.open "Logon", conn, 2, 2
'Use the addnew method of the recordset object to add a record
rs.addnew
'Set the table column = to my input text box from my form
rs("LogonID"
= request("LogonID"
rs("Password"
= request("Password"
rs.update
'I do a movelast here to get the ID that is automatically generated
'I also set the value to a local variable so I can write out to the database
rs.movelast
end if
%>
<%
'Always! Always set your objects to nothing. This clears them out of servers memory
'Your network admins will like this
set rs= nothing
set conn = nothing
%>
</BODY>
</html>
<%@ Language = "VBScript"%>
<%
Public Valid
valid = false
%>
<HTML>
<HEAD>
<META name=VI60_defaultClientScript content=VBScript>
<TITLE>AIR</TITLE>
<SCRIPT LANGUAGE=VBscript>
<!--option explicit
function Validate()
dim Logon
dim Flag
valid = false
Flag = false
Logon = document.AIR1.txtLogonID.value
Password = document.AIR1.txtPassword.value
if Logon = "" then
msgbox "Enter in Your Logon ID",,"No Logon ID"
else
if Isnumeric(Logon) then
msgbox "There must me alpha characters in your Logon ID",,"Invalid Data"
else
if password = "" then
msgbox "No Password was Entered",,"Need Password"
else
flag = true
valid = true
end if
end if
end if
end function
-->
</SCRIPT>
</HEAD>
<BODY bgColor=silver>
<FORM METHOD="post" NAME="AIR1">
<p> </p>
<strong><u>AIR</u></strong>
<P>
Logon ID: <INPUT NAME="LogonID" id=txtLogonID><br>
Password: <INPUT NAME="Password" id=txtPassword> </P>
<P id=frmAIR> <br> </P>
<input id =cmdSubmit type=submit value=submit name=button1 onclick = validate()>
</FORM>
<%
if valid = true then
'Declaring variables
'Opening and connecting to data
dim conn
dim rs
dim strID
dim strconn
'set a local variable to my DSN-less connection String
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" & Server.MapPath("TPL.mdb"
'Create the Connection object
set conn = server.createobject("adodb.connection"
conn.open strconn
'Create the recordset object
set rs = server.createobject("adodb.recordset"
'This statement opens the table so we can add a record notice the addnew
'The 2, 2 is how the table is opened there are many ways it can be opened
rs.open "Logon", conn, 2, 2
'Use the addnew method of the recordset object to add a record
rs.addnew
'Set the table column = to my input text box from my form
rs("LogonID"
rs("Password"
rs.update
'I do a movelast here to get the ID that is automatically generated
'I also set the value to a local variable so I can write out to the database
rs.movelast
end if
%>
<%
'Always! Always set your objects to nothing. This clears them out of servers memory
'Your network admins will like this
set rs= nothing
set conn = nothing
%>
</BODY>
</html>