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

Insert data could not be process 1

Status
Not open for further replies.

senadaulay

Programmer
Feb 4, 2004
29
ID
Hi,I'm New using ASP program so bare with me.I need to create a form so i can entry data to the table in Access. the database i use is Access, the connection using ODBC.to insert the data I'm using SQL syntax, but it's doesn't work. maybe someone could help me. heres my code.

If Request.Form ("Submit") = "submit1" Then
intNo = Request.Form ("No")
varEmployeeNo = Request.Form ("EmployeeNo")
varSurname = Request.Form ("Surname")
varGivenName = Request.Form ("GivenName")

Session("Nomer") = intNomer
Session ("EmployeeNo") = varEmployeeNo
Session ("Surname") = varSurname
Session ("GivenName") = varGivenName

Set Conn = Server.CreateObject ("ADODB.Connection")
Conn.Open "DSN=MRegisterTbl"
Conn.Execute (strsql)

strsql="INSERT INTO Expat_EmployeeReg(No,EmployeeNo,Surname,GivenName,Address,WorkLocation,ProjectNo,Citizen,DateofBirth,GovernmentPosition)" &_
"VALUES('" & intNo & "','" & varEmployeeNo & "','" & varSurname & "','" & varGivenName & "','" & varAddress & "','" & varWorkLocation & "','" & varProjectNo & "','" & varCitizen & "','" & varDateofBirth & "','" & varGovernmentPosition & "')"
Conn.Execute strsql

thank's for the help
 
Conn.Execute (strsql)

is before


strsql="INSERT INTO Expat_EmployeeReg(No,EmployeeNo,Surname,GivenName,Address,WorkLocation,ProjectNo,Citizen,DateofBirth,GovernmentPosition)" &_
"VALUES('" & intNo & "','" & varEmployeeNo & "','" & varSurname & "','" & varGivenName & "','" & varAddress & "','" & varWorkLocation & "','" & varProjectNo & "','" & varCitizen & "','" & varDateofBirth & "','" & varGovernmentPosition & "')"
Conn.Execute strsql


hth,
Foxbox
ttmug.gif
 
Hi Foxbox...thank's for your replay
I did try your suggestion, but it's still doesn't work. every time i summit the form the datas doesn't save to the table.if in my table have two column for Number where the data type is auto Number the other is Number, is that could be a problem? or maybe you could give me other suggestion so i can check my code?
actually i have 2 forms. my first form is for entry data and the second form for view the data where i will put links so when the user want to add,update dan delete data it will open the first form.i hope its make any sense
thank's
 
a) you can not update/insert a value in an autonumber b)field.
b) Is "No" a numeric field? if yes: you have ' ' around it
c) Same for EmployeeNo
d) idem projectNo
e) Your code shows how 7 variables receive a value (
intNo = Request.Form ("No") etc), but in the SQL i see 10 variables....
f) Session("Nomer") = intNomer is not used at all
g) You store 4 variables into session()'s, but it is not clear how the variables received a value:

varEmployeeNo = requestr.form("employeeno") ' ?
Session ("EmployeeNo") = varEmployeeNo

h) If the <INPUT> fields are on form 1, you retrieve them on form 2 with request.form() . But when the user presses the Add link, your ADD.ASP can not use Request.Form () to get the values from form 1. You need 1) <INPUT TYPE=HIDDEN> fields in form 2 or 2) store the form 1 values in session() variables (in form 2). Your code shows a mix of both, which suggests that you have some fields on form 1 and some on form 2..







hth,
Foxbox
ttmug.gif
 
I forget to tell you that i have a lot of fields in my table so i only show you 7 fields...sorry about that.
so for the field with data type with autonumber i still need to declare it but not put it in SQL syntax right?
in point G) you mention that it is not clear how the variables received a value i'm not sure how to do this,but
I have been trying following your suggestion and still not working,this is the code that i have been working on it, could you check it out please....

as in form 1 the code i put like this:
<! --#include file=&quot;Source.asp&quot; -->
<%
Dim intAngka,intNomer,varEmployeeNo,varSurname,varGivenName Dim varStatus, varSection, varAddress, varHired_date
Dim strConnect, rsData, Conn, strSQl

If Request.Form(&quot;submit1&quot;)= &quot;submit1&quot; Then
intNomer = Session(&quot;Nomer&quot;)(the data type is number)
varEmployeeNo = Session (&quot;EmployeeNo&quot;)
varSurname = Session (&quot;Surname&quot;)
varGivenName = Session (&quot;GivenName&quot;)
varStatus = Session (&quot;Status&quot;)
varSection = Session (&quot;Section&quot;)
varAddress = Session (&quot;Address&quot;)
varHired_date = Session (&quot;DateofHired&quot;)

Set Conn = Server.CreateObject (&quot;ADODB.Connection&quot;)
Conn.Open &quot;DSN=Insert&quot;

strsql =&quot;INSERT INTO Expat_EmployeeReg &quot; &_
&quot;(Nomer,Surname,GivenName,Status,EmployeeNo, &quot; & _
&quot;Section,DateofHired,Address)&quot; & _
&quot;VALUES (&quot; &_
&quot;'&intNomer&','&quot; & varSurname & &quot;','&quot; & varGivenName & &quot;','&quot; & varStatus & &quot;','&quot; & varEmployeeNo & &quot;', &quot; & _
&quot;'&quot; & varSection & &quot;','&quot; & varHired_date & &quot;','&quot; & varAddress & &quot;')&quot;
Conn.Execute strSql
Response.Redirect (&quot;ViewData.asp&quot;)

If rsData.State then
rsData.Close
end if
set rsData= Nothing

If Conn.State then
Conn.Close
set Conn= Nothing
end if
end if
%>
<TR>
<TD bgColor=#30c2f0> No :</TD>
<TD bgColor=#30c2f0><INPUT id=text2
style=&quot;WIDTH: 65px; HEIGHT: 22px&quot; size=9 name=&quot;Nomer&quot;
></TD></TR>
<TR>
<TD bgColor=#30c2f0>Employee No :</TD>
<TD bgColor=#30c2f0><INPUT id=text2
style=&quot;WIDTH: 65px; HEIGHT: 22px&quot; size=9 name=&quot;EmployeeNo&quot;
></TD></TR>
<P><INPUT id=submit1 style=&quot;WIDTH: 63px; HEIGHT: 34px&quot; type=submit size=21 value=Submit name=submit1>&>
</FORM>
</BODY>
</HTML>

this is form 2 code:
<%
Dim intAngka,intNomer,varEmployeeNo,varSurname,varGivenName Dim varStatus, varSection, varAddress, varHired_date
Dim strConnect, rsData, Conn, strSQl, i

Session (&quot;Nomer&quot;) = intNomer
Session (&quot;EmployeeNo&quot;) = varEmployeeNo
Session (&quot;Surname&quot;) = varSurname
Session (&quot;GivenName&quot;) = varGivenName
Session (&quot;Status&quot;)= varStatus
Session (&quot;Section&quot;) = varSection
Session (&quot;Address&quot;) = varAddress
Session (&quot;DateofHired&quot;) = varHired_date

Set Conn = Server.CreateObject (&quot;ADODB.Connection&quot;)
Conn.Open &quot;DSN=Insert&quot;
Set rsData = Server.CreateObject (&quot;ADODB.Recordset&quot;)
rsData.Open &quot;SELECT * FROM Expat_EmployeeReg&quot;, Conn

i=1
%>
<TH>Nomer</TH>
<TH>EmployeeNo</TH>
<TH>Surname</TH>
<TH>GivenName</TH>
<TH>Status</TH>
<TH>Section</TH>
<TH>Address</TH>
<TH>DateofHired</TH>
<%
Do While Not rsData.EOF
%>
<TR>
<TD><%=i%></TD>
<TD><%=rsData(&quot;EmployeeNo&quot;)%></TD>
<TD><%=rsData(&quot;Surname&quot;)%></TD>
<TD><%=rsData(&quot;GivenName&quot;)%></TD>
<TD><%=rsData(&quot;Status&quot;)%></TD>
<TD><%=rsData(&quot;Section&quot;)%></TD>
<TD><%=rsData(&quot;Address&quot;)%></TD>
<TD><%=rsData(&quot;DateofHired&quot;)%></TD>

<INPUT TYPE=hidden name=&quot;Nomer&quot; value=<%session(&quot;Nomer&quot;)%>>
<INPUT TYPE=hidden name=&quot;EmployeeNo&quot; value=<%session(&quot;EmployeeNo&quot;)%> >
<INPUT TYPE=hidden name=&quot;Surname&quot; value=<%session(&quot;Surname&quot;%>>
<INPUT TYPE=hidden name=&quot;GivenName&quot; value=<%session(&quot;GivenName&quot;)%>>
<INPUT TYPE=hidden name=&quot;Status&quot; value=<%session(&quot;Status&quot;)%> >
<INPUT TYPE=hidden name=&quot;Section&quot; value=<%session(&quot;Section&quot;)%>>
<INPUT TYPE=hidden name=&quot;Address&quot; value=<%session(&quot;Address&quot;)%>>
<INPUT TYPE=hidden name=&quot;DateofHired&quot; value=<%session(&quot;DateofHired&quot;)%>>

<%
i = i + 1
rsData.MoveNext
Loop
rsData.Close
Conn.Close
Set rsData= Nothing
Set Conn= Nothing

%>
</TABLE>
</FORM>
</BODY>
</HTML>

thank's
 
Code:
<%
If Request.ServerVariables(&quot;REQUEST_METHOD&quot;) = &quot;POST&quot; then
 dim intNomer, varEmployeeNo
  
 ' Store nomer in session variable, because you need
 ' it on the 2nd form
 session(&quot;sIntNomer&quot;) = request.Form(&quot;nomer&quot;)
 
 ' Build the SQL. Use request.form(); no need to store
 ' them first in variables (but you may consider
 ' additional input validation)
 strsql =&quot;INSERT INTO Expat_EmployeeReg &quot; &_ 
         &quot;(Nomer,EmployeeNo) VALUES (&quot; &_
         session(&quot;sNomer&quot;) & &quot;,'&quot; &_
         request.Form(&quot;EmployeeNO&quot;) & &quot;')&quot;
 Conn.Execute strSql 
 ' CLOSE CONNECTION FIRST!
 conn.close

 ' THEN TO 2ND FORM. 
 Response.Redirect (&quot;form2.asp&quot;)   
 response.End   
end if
%>
<form action=index.asp method=post>
 No          : <INPUT  id=text2 size=9 name=&quot;Nomer&quot; ><br> 
 Employee No : <INPUT size=9 name=&quot;EmployeeNo&quot;><br>
 <br>
 <INPUT type=submit value=&quot;Submit&quot;>
</FORM>
</BODY>
</HTML>


Form2.asp

Code:
<%
' i suppose you want to display 1 record from Expat_employeeReg
' Your SQL needs a WHERE:
strSQL = &quot;SELECT TOP 1 * FROM Expat_EmployeeReg where &quot; &_
         &quot;nomer = &quot; &  session(&quot;sIntNomer&quot;)
Set Conn = Server.CreateObject (&quot;ADODB.Connection&quot;)
Conn.Open &quot;DSN=Insert&quot;
Set rsData = Server.CreateObject (&quot;ADODB.Recordset&quot;)
rsData.Open strSQL, Conn

' And now the rsData recordset containts all the values
' of your just INSERTed record
%>
<table>
<tr>
<td>Field</td>
<td>Content</td>
</tr>

<tr>
<td>Nomer</td>
<td><%= rsData(&quot;nomer&quot;) %></td>
</tr>

<td>EmployeeNo</td>
<TD><%= rsData(&quot;EmployeeNo&quot;) %></TD>
</tr>

rsData.Close 
Conn.Close 
Set rsData= Nothing
Set Conn= Nothing
</TABLE> 
</FORM>
</BODY>
</HTML>




hth,
Foxbox
ttmug.gif
 
I try your suggestion and this is my new code after i follow your code, i dont know why is still doesn't work with me.did i miss something? i really appreciate your patience, i input some of my data in my first form and submit the second form come up and the new values doesn't shows in the second form.
the things is there are no error message until i refresh the second form and i got error message like this:

Error Type:
Provider (0x80004005)
Unspecified error
/Nur/Extra_HRD/Data_Emp.asp, line 25

Browser Type:
Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)

Page:
POST 706 bytes to /Nur/Extra_HRD/Data_Emp.asp

POST Data:
Nomer=2&EmployeeNo=786&Surname=Daulay&GivenName=Nursena&Status=Permanent+Employee&Section=ENC&Address=kemang&WorkLocation=Jakarta&DateofHired=&ProjectNo=&Citizen=&PlaceofBirth=&DateofBirth=&Government . . .

<%
If Request.ServerVariables (&quot;REQUEST_METHOD&quot;) = &quot;POST&quot; then
Dim intNomer, varEmployeeNo, varSurname, varGivenName
Dim varStatus, varSection, varWorkLocation

Session (&quot;intNomer&quot;) = Request.Form (&quot;Nomer&quot;)
strsql = &quot;INSERT INTO Expat_EmployeeReg &quot; &_
&quot;(Nomer,Surname,GivenName,Status,EmployeeNo &quot; & _
&quot;WorkLocation,Section) VALUES (&quot; &_
session(&quot;intNomer&quot;) & &quot;, '&quot; &_
Request.Form(&quot;Surname&quot;)&&quot;','&quot;&Request.Form(&quot;GivenName&quot;)&&quot;','&quot;&Request.Form(&quot;Status&quot;)&&quot;','&quot;&Request.Form(&quot;EmployeeNo&quot;)&&quot;', '&quot;& _
Request.Form(&quot;WorkLocation&quot;)&&quot;','&quot;&Request.Form(&quot;Section&quot;)&&quot;')&quot;

Conn.Execute strsql
Conn.Close

Response.Redirect (&quot;Data_Emp.asp&quot;)
Response.End
End If
%>
<FORM ACTION=&quot;Data_Emp.asp&quot; METHOD=Post>
<BODY>
<TR>
<TD bgColor=#30c2f0>Nomer :</TD>
<TD bgColor=#30c2f0><INPUT id=text1
style=&quot;WIDTH: 41px; HEIGHT: 22px&quot; size=5 name=&quot;Nomer&quot;
></TD></TR>
<TR>
<TD bgColor=#30c2f0>Employee No :</TD>
<TD bgColor=#30c2f0><INPUT id=text2
style=&quot;WIDTH: 65px;HEIGHT: 22px&quot;size=9 name=&quot;EmployeeNo&quot;
></TD></TR>
<TR>
<TD bgColor=#30c2f0>Surname :</TD>
<TD bgColor=#30c2f0><INPUT id=text3
style=&quot;WIDTH: 193px; HEIGHT: 22px&quot; size=27 name=&quot;Surname&quot;
></TD></TR>

these are my second form code:

<%
Dim intAngka, intNomer, varEmployeeNo, varSurname, varGivenName
Dim varStatus, varSection, varWorkLocation

strSQL = &quot;SELECT * FROM Expat_EmployeeReg&quot;

Set Conn = Server.CreateObject (&quot;ADODB.Connection&quot;)
Conn.Open &quot;DSN=Insert&quot;, Conn

Set rsData = Server.CreateObject (&quot;ADODB.Recordset&quot;)
rsData.Open strSQL,Conn
%>
TR>
<TH>Nomer</TH>
<TH>EmployeeNo</TH>
<TH>Surname</TH>
<TH>GivenName</TH>
<TH>Status</TH>
<TH>Section</TH>
<TH>WorkLocation</TH>

<TD><%=rsData(&quot;Nomer&quot;)%></TD>
<TD><%=rsData(&quot;EmployeeNo&quot;)%></TD>
<TD><%=rsData(&quot;Surname&quot;)%></TD>
<TD><%=rsData(&quot;GivenName&quot;)%></TD>
<TD><%=rsData(&quot;Status&quot;)%></TD>
<TD><%=rsData(&quot;Section&quot;)%></TD>
<TD><%=rsData(&quot;WorkLocation&quot;)%></TD>

<%

rsData.Close
Conn.Close
Set rsData= nothing
Set Conn= nothing
%>

thank's
 
after the INSERT into i see a
Code:
Response.Redirect (&quot;Data_Emp.asp&quot;)

but a few lines down, i see:
Code:
<FORM ACTION=&quot;Data_Emp.asp&quot; METHOD=Post>

which suggest that this in fact is Data_emp.asp!
You must redirect to the 2nd page....

Your 2nd page code does not look like my form2.asp
I still see a
Code:
strSQL = &quot;SELECT * FROM Expat_EmployeeReg&quot;
which is retrieving all records from that table....


hth,
Foxbox
ttmug.gif
 
Thanks Foxbox for your help...I figure out that in my program I could not use DSN I don't know why, so I change my database connection to Microsoft Jet OLEDB 4.0 and I also put my access table in the wrong directory.
If you dont mind I have another question,
I have to make some changes in my field.
I'm not using &quot;Nomer&quot; filed anymore.
I did some revision with my code but most of it I'm following your code. I told you before i only have 2 form but know I add one more form. the scenario little bit changes...In Form 1 just enter the new data. Form 2nd will be show the new Data,in form2 If the user doesn't want to save the data they still can do it by click the cancel button which is still goto confirm page but will be show different message and so does if the data will be save
it will goto form 3 (Confirmation page)where there will message said that Data have been save.
I want to ask :
1. is it right in form 2 where I put the insert and select statement?
2. i know you told me before for show the data using select top 1...but if I want to show the current data
after i input data from form 1. I try using strsql = &quot;select * from insert where EmployeeID= '&quot;&amp;varID&amp;&quot;'&quot;
3. in form 3 (confirmation page) what should i put in there?
just check status? like : If strTo &gt;= 1 then status 'save'?
here's my code:
form1.asp
&lt;%
If Request.ServerVariables(&quot;REQUEST_METHOD&quot;) = &quot;POST&quot; then
Dim varID, varName, varAddress
Dim varPhome, intPostal, varSalary
Dim strsql
Dim Conn
Dim strConnect

varID = Request.Form (&quot;EmployeeID&quot;)
varName = Request.Form (&quot;EmployeeName&quot;)
varAddress = Request.Form (&quot;EmployeeAddress&quot;)
varPhome = Request.Form (&quot;EmployeePhoneHome&quot;)
intPostal = Request.Form (&quot;EmployeePostalCode&quot;)
varSalary = Request.Form (&quot;EmployeeSalary&quot;)

strConnect= &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TblEmploy.mdb&quot;

Set Conn= Server.CreateObject (&quot;ADODB.Connection&quot;)
Conn.Open strConnect

strSQL = &quot;INSERT INTO Data(EmployeeID,EmployeeName, &quot; &amp; _
&quot;EmployeeAddress, EmployeePhoneHome,
EmployeePostalCode, EmployeeSalary) &quot; &amp; _
&quot;VALUES('&quot; &amp; Cstr(Request.Form(&quot;EmployeeID&quot;)) &amp; &quot;','&quot; &amp; _
Cstr(Request.Form(&quot;EmployeeName&quot;)) &amp; &quot;','&quot; &amp; _
Cstr(Request.Form(&quot;EmployeeAddress&quot;)) &amp; &quot;','&quot; &amp; _
Cstr(Request.Form(&quot;EmployeePhoneHome&quot;)) &amp; &quot;','&quot; &amp; _
Cstr(Request.Form(&quot;EmployeePostalCode&quot;)) &amp; &quot;',&quot; &amp; _
CCur(Request.Form(&quot;EmployeeSalary&quot;)) &amp; &quot;)&quot;
Response.Write strSQL
Conn.Execute strSQL
Conn.Close
Response.Redirect(&quot;ResultADD.asp&quot;)
Response.End
End IF
%&gt;
&lt;FORM ACTION=ADD_Employee.asp METHOD=post Name=frmAdd&gt;
&lt;TR&gt;&lt;TD&gt;EmployeeID&lt;/TD&gt;
&lt;TD&gt;&lt;INPUT name=&quot;EmployeeID&quot; &gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;&lt;P&gt;EmployeeName&lt;/P&gt;&lt;/TD&gt;
&lt;TD&gt;&lt;INPUT name=&quot;EmployeeName&quot; &gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;EmployeeAddress&lt;/TD&gt;
&lt;TD&gt;&lt;INPUT name=&quot;EmployeeAddress&quot; &gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;EmployeePhoneHome&lt;/TD&gt;
&lt;TD&gt;&lt;INPUT name=&quot;EmployeePhoneHome&quot; &gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;EmployeePostalCode&lt;/TD&gt;
&lt;TD&gt;&lt;SELECT type=&quot;dropdown&quot; name=&quot;EmployeePostalCode&quot; style=&quot;WIDTH: 154px&quot;&gt; &lt;OPTION selected&gt;
&lt;OPTION&gt;1234&lt;/OPTION&gt;
&lt;OPTION&gt;2345&lt;/OPTION&gt;&lt;/SELECT&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;EmployeeSalary&lt;/TD&gt;
&lt;TD&gt;&lt;INPUT name=&quot;EmployeeSalary&quot; &gt;&lt;/TD&gt;&lt;/TR&gt;

&lt;/TABLE&gt;&lt;/P&gt;
&lt;P&gt;&lt;INPUT type=submit value=Submit name=submit1&gt;
&lt;INPUT id=reset1 type=reset value=Reset name=reset1&gt;&lt;/P&gt;

form2.asp
&lt;%
strConnect= &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TblEmploy.mdb&quot;

Set Conn= Server.CreateObject (&quot;ADODB.Connection&quot;)
Conn.Open strConnect

Set rsData = Server.CreateObject (&quot;ADODB.Recordset&quot;)
strsql &quot;SELECT * FROM Data WHERE Employee Where EmployeeID= '&quot;&amp;varID&amp;&quot;'&quot;
Conn.Execute strSQL
%&gt;
&lt;TR&gt;&lt;TD&gt;EmployeeID&lt;/TD&gt;
&lt;TD&gt;&lt;%=rsData(&quot;EmployeeID&quot;)%&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;EmployeeName&lt;/TD&gt;
&lt;TD&gt;&lt;%=rsData(&quot;EmployeeName&quot;)%&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;EmployeeAddress&lt;/TD&gt;
&lt;TD&gt;&lt;%=rsData(&quot;EmployeeAddress&quot;)%&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;EmployeePHome&lt;/TD&gt;
&lt;TD&gt;&lt;%=rsData(&quot;EmployeePhoneHome&quot;)%&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;EmployeePostalCode&lt;/TD&gt;
&lt;TD&gt;&lt;%=rsData(&quot;EmployeePostalCode&quot;)%&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;EmployeeSalary&lt;/TD&gt;
&lt;TD&gt;&lt;%=rsData(&quot;EmployeeSalary&quot;)%&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;/TABLE&gt;
&lt;INPUT id=submit1 type=submit size=21 value=Update name=submit1&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;
&lt;INPUT id=reset1 type=reset size=33 value=Cancel name=reset1&gt;&lt;/P&gt;
&lt;%
rsData.Close
Conn.Close
Set rsData= nothing
Set Conn= nothing
%&gt;
&lt;/BODY&gt;
thank's
 
Based on the code above 'form1.asp' = ADD_Employee.asp
and form2.asp = ResultADD.asp.

In Form1 i see:
&lt;FORM ACTION=ADD_Employee.asp METHOD=post Name=frmAdd&gt;
so after hitting submit we re-enter the same page and the INSERT is executed!
after that i see a
Response.Redirect(&quot;ResultADD.asp&quot;) (aka form2)

There your SQL looks wrong because varID has no value (you assigned in form1, but we left there and are now in form2)

&quot;Top 1&quot; in SQL is just an instruction to give only the first record that meets the WHERE. We SELECT using a unique key, so even without &quot;TOP 1&quot; you only select 1 record; i use it for optimum performance.

Your 2nd form has no &lt;FORM&gt; tag, so after hitting SUBMIT the page does not know where to go.

You display information, so a RESET button is also obsolete.

And finally: you did the insert already in form1!

You need to change the program flow:

FORM1: enter information (in a &lt;FORM action=FORM1.ASP&gt;), after SUBMIT (re-entering FORM1) and display the information (in a &lt;FORM action=FORM2.ASP &gt;), and put an INSERT and CANCEL button under it.
After hitting INSERT go to FORM2 and do the actual INSERT




















hth,
Foxbox
ttmug.gif
 
I still need your help FoxBox....I have been working with my code....here the code that I have been modify but still not working...

in Form 1 I didn't put any kind of code...just INPUT tag.
in form 2
Set Conn = Server.CreateObject (&quot;ADODB.CONNECTION&quot;)
Set rsData = Server.CreateObject (&quot;ADODB.Recordset&quot;)
Conn.Open &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TblEmploy.mdb&quot;
rsData.Open &quot;Data&quot;, Conn
strsql = &quot;Select * from Data &quot;
strsql=strsql &amp; &quot;where EmployeeID='&quot; &amp; varID&amp; &quot;'&quot;
Set rsData = Conn.Execute(strsql)

If Request.Form (&quot;submit1&quot;) = &quot;Save&quot; then

strsql = &quot;INSERT INTO Data(EmployeeID,EmployeeName, &quot; &amp; _
&quot;EmployeeAddress, EmployeePhoneHome, EmployeePostalCode, EmployeeSalary) &quot; &amp; _
&quot;VALUES('&quot; &amp; Cstr(Request.Form(&quot;EmployeeID&quot;)) &amp; &quot;','&quot; &amp; _
Cstr(Request.Form(&quot;EmployeeName&quot;)) &amp; &quot;','&quot; &amp; _
Cstr(Request.Form(&quot;EmployeeAddress&quot;)) &amp; &quot;','&quot; &amp; _
Cstr(Request.Form(&quot;EmployeePhoneHome&quot;)) &amp; &quot;','&quot; &amp; _
Cstr(Request.Form(&quot;EmployeePostalCode&quot;)) &amp; &quot;',&quot; &amp; _
CCur(Request.Form(&quot;EmployeeSalary&quot;)) &amp; &quot;)&quot;
Conn.Execute strsql
Conn.Close

If Not rsData.EOF then

%&gt;
&lt;TR&gt;&lt;TD&gt;EmployeeName&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;&lt;%=rsData(&quot;EmployeeName&quot;)%&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;EmployeeAddress&lt;/TD&gt;
&lt;TD&gt;&lt;%=rsData(&quot;EmployeeAddress&quot;)%&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;EmployeePHome&lt;/TD&gt;
&lt;TD&gt;&lt;%=rsData(&quot;EmployeePhoneHome&quot;)%&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;EmployeePostalCode&lt;/TD&gt;
&lt;TD&gt;&lt;%=rsData(&quot;EmployeePostalCode&quot;)%&gt;&lt;/TD&gt;&lt;/TR&gt;
&lt;TR&gt;&lt;TD&gt;EmployeeSalary&lt;/TD&gt;
&lt;TD&gt;&lt;%=rsData(&quot;EmployeeSalary&quot;)%&gt;&lt;/TD&gt;&lt;/TR&gt;   

&lt;%
end if
end if
%&gt;

but when I run the code I got error message like this:
Error Type:
Error Type:
Microsoft JET Database Engine (0x80040E07)
Data type mismatch in criteria expression.
/Nur/Project1_ASP/ResultADD.asp, line 29

Browser Type:
Mozilla/4.0 (compatible; MSIE 5.5; Windows NT 5.0)

Page:
POST 137 bytes to /Nur/Project1_ASP/ResultADD.asp

POST Data:
EmployeeID=411&amp;EmployeeName=BoB&amp;EmployeeAddress=Bunga&amp;EmployeePhoneHome=7868686&amp;EmployeePostalCode=2345&amp;EmployeeSalary=100&amp;submit1=Submit

I did check my field in my table and the filed name is same

thanks
 
this is one way to do what you want:

FORM1.ASP:
Code:
<html>
<h1>FORM1/STEP 1: INPUT</h1>
<form action=form2.asp method=post>
Enter a name:<br>
<input type=text name=fName value="<%= session("sName") %>">
<br>
<input type=submit value=OK>
</form>
</html>
(The first time you enter this form, the session has no value, so an empty field is presented.)



FORM2.ASP:
Code:
<html>
<h1>FORM2/STEP 2: CHECK</h1>
<form action=form3.asp method=post>
Your input:<br>
<%
' store the imput from the previous schreen in
' session variable
session("sName") = Request.Form("fName")
Response.Write "<b>" & session("sName") & "</b>"
%>
<br>
<br>
<input type=submit value=INSERT>&nbsp;
<input type=button value=EDIT OnClick="location.href='form1.asp'">
</form>
</html>
(When the user hits the EDIT button, you go back to FORM1.ASP, and now the session variable is used to present the original input)


FORM3.ASP:
Code:
<%
' Open database connection

' Create SQL statement:
' strSQL = "INSERT INTO data(name) " &_
         ' "values('" & session("sName") & "')"
' conn.execute strSQL
' conn.close
' set conn= nothing

' reset the session:
session("sName") = ""

' when you want direct to a menu or step 1: put 
' a response.redirect here.
' if we ommit that, the rest of the page is processed....
%>
<html>
<h1>FORM3/STEP 3: INSERT</h1>
Your input:<br>
<%
Response.Write "<b>" & session("sName") & "</b>"
%>
was saved to the database.
<br>
<br>
<input type=button value=AGAIN OnClick="location.href='form1.asp'">
</form>
</html>


ttmug.gif
 
thank you..thank you so much Foxbox..I appreciate your help and your patince....thank's
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top