I have a form that I am trying to get to insert into an Access Database with ASP. Below I am inserting the code parts of my ASP pages. The form code is here:
demo.asp
-------------------------------------------------------
<%
Dim path
Dim conn
Dim query
Dim formtype
Dim id
Dim first
Dim last
Dim email
Dim address
Dim city
Dim state
Dim zip
Dim phone
path = Server.MapPath("/database/demo.mdb"
Set conn = Server.CreateObject("ADODB.Connection"
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";"
id = Request("id"
if (id = ""
then
id = 0
end if
Set query = conn.Execute("SELECT * FROM demo_table WHERE id = " & id)
if query.EOF then
formtype = "add"
first = ""
last = ""
email = ""
address = ""
city = ""
state = ""
zip = ""
phone = ""
else
formtype = "update"
first = query.Fields("first"
.value
last = query.Fields("last"
.value
email = query.Fields("email"
.value
address = query.Fields("address"
.value
city = query.Fields("city"
.value
state = query.Fields("state"
.value
zip = query.Fields("zip"
.value
phone = query.Fields("phone"
.value
end if
%>
<!--------FORM-------------->
<form method="post" action="submit_success.asp">
<input name="formtype" type="hidden" value="<%=add%>">
<table width=500 border=0 align=center>
<tr>
<td>
<table align="left" cellspacing="3" cellpadding="0">
<tr>
<td align="left" width=75><font face=arial size=2>First Name</font></td>
<td align="left">
<input type="text" name="first" maxlength="100" size="20" value="<%=first%>">
</td>
</tr>
<tr>
<td align="left" width=75><font face=arial size=2>Last Name</font></td>
<td align="left">
<input type="text" name="last" maxlength="100" size="20" value="<%=last%>">
</td>
</tr>
<tr>
<td align="left" width=75><font face=arial size=2>Address</font></td>
<td align="left">
<input type="text" name="address" maxlength="100" size="20" value="<%=address%>">
</td>
</tr>
<tr>
<td align="left" width=75><font face=arial size=2>City</font></td>
<td align="left">
<input type="text" name="city" maxlength="100" size="20" value="<%=city%>">
</td>
</tr>
<tr>
<td align="left" width=75><font face=arial size=2>State</font></td>
<td align="left">
<input type="text" name="state" maxlength="100" size="2" value="<%=state%>">
</td>
</tr>
<tr>
<td align="left" width=75><font face=arial size=2>Zip</font></td>
<td align="left">
<input type="text" name="zip" maxlength="100" size="10" value="<%=zip%>">
</td>
</tr>
<tr>
<td align="left" width=75><font face=arial size=2>e-Mail</font></td>
<td align="left">
<input type="text" name="email" maxlength="100" size="20" value="<%=email%>">
</td>
</tr>
<tr>
<td align="left" width=75><font face=arial size=2>Phone</font></td>
<td align="left">
<input type="text" name="phone" maxlength="100" size="20" value="<%=phone%>"> <input type = "submit" value = "Submit">
</td>
</tr>
</table>
</td></tr></table>
</form>
<!------END-FORM----------------->
-------------------------------------------------------
This form then sends the information to this ASP file called "Submit_Success.asp." THis inserts with a SIMPLE INSERT STATEMENT (this is where the problem has arisen) into the access database. The problem seems to be lying in the Insert statement line below.
-------------------------------------------------------
<%
Dim path
Dim conn
path = Server.MapPath("/database/demo.mdb"
Set conn = Server.CreateObject("ADODB.Connection"
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";"
Dim formtype
Dim id
Dim thefirst
Dim thelast
Dim thestate
Dim thecity
Dim theaddress
Dim thephone
Dim thezip
Dim theemail
formtype = Request.Form("formtype"
thefirst = Replace(Request.Form("first"
, "'", "'"
thelast = Replace(Request.Form("last"
, "'", "'"
thestate = Replace(Request.Form("state"
, "'", "'"
thecity = Replace(Request.Form("city"
, "'", "'"
theaddress = Replace(Request.Form("address"
, "'", "'"
thephone = Replace(Request.Form("phone"
, "'", "'"
thezip = Replace(Request.Form("zip"
, "'", "'"
theemail = Replace(Request.Form("email"
, "'", "'"
Dim query
Set query = conn.Execute("INSERT INTO demo_table (first, last, address, city, state, zip, email, phone) VALUES ('" & thefirst & "', '" & thelast & "', '" & theaddress & "', '" & thecity & "', '" & thestate & "', '" & thezip & "', '" & theemail & "', '" & thephone & "')"
conn.Close
Set conn = Nothing
Response.Redirect "/demo/demo_view.asp"
%>
----------------------------------------------------------
Here is a link to my access database on a testing server...
demo.asp
-------------------------------------------------------
<%
Dim path
Dim conn
Dim query
Dim formtype
Dim id
Dim first
Dim last
Dim email
Dim address
Dim city
Dim state
Dim zip
Dim phone
path = Server.MapPath("/database/demo.mdb"
Set conn = Server.CreateObject("ADODB.Connection"
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";"
id = Request("id"
if (id = ""
id = 0
end if
Set query = conn.Execute("SELECT * FROM demo_table WHERE id = " & id)
if query.EOF then
formtype = "add"
first = ""
last = ""
email = ""
address = ""
city = ""
state = ""
zip = ""
phone = ""
else
formtype = "update"
first = query.Fields("first"
last = query.Fields("last"
email = query.Fields("email"
address = query.Fields("address"
city = query.Fields("city"
state = query.Fields("state"
zip = query.Fields("zip"
phone = query.Fields("phone"
end if
%>
<!--------FORM-------------->
<form method="post" action="submit_success.asp">
<input name="formtype" type="hidden" value="<%=add%>">
<table width=500 border=0 align=center>
<tr>
<td>
<table align="left" cellspacing="3" cellpadding="0">
<tr>
<td align="left" width=75><font face=arial size=2>First Name</font></td>
<td align="left">
<input type="text" name="first" maxlength="100" size="20" value="<%=first%>">
</td>
</tr>
<tr>
<td align="left" width=75><font face=arial size=2>Last Name</font></td>
<td align="left">
<input type="text" name="last" maxlength="100" size="20" value="<%=last%>">
</td>
</tr>
<tr>
<td align="left" width=75><font face=arial size=2>Address</font></td>
<td align="left">
<input type="text" name="address" maxlength="100" size="20" value="<%=address%>">
</td>
</tr>
<tr>
<td align="left" width=75><font face=arial size=2>City</font></td>
<td align="left">
<input type="text" name="city" maxlength="100" size="20" value="<%=city%>">
</td>
</tr>
<tr>
<td align="left" width=75><font face=arial size=2>State</font></td>
<td align="left">
<input type="text" name="state" maxlength="100" size="2" value="<%=state%>">
</td>
</tr>
<tr>
<td align="left" width=75><font face=arial size=2>Zip</font></td>
<td align="left">
<input type="text" name="zip" maxlength="100" size="10" value="<%=zip%>">
</td>
</tr>
<tr>
<td align="left" width=75><font face=arial size=2>e-Mail</font></td>
<td align="left">
<input type="text" name="email" maxlength="100" size="20" value="<%=email%>">
</td>
</tr>
<tr>
<td align="left" width=75><font face=arial size=2>Phone</font></td>
<td align="left">
<input type="text" name="phone" maxlength="100" size="20" value="<%=phone%>"> <input type = "submit" value = "Submit">
</td>
</tr>
</table>
</td></tr></table>
</form>
<!------END-FORM----------------->
-------------------------------------------------------
This form then sends the information to this ASP file called "Submit_Success.asp." THis inserts with a SIMPLE INSERT STATEMENT (this is where the problem has arisen) into the access database. The problem seems to be lying in the Insert statement line below.
-------------------------------------------------------
<%
Dim path
Dim conn
path = Server.MapPath("/database/demo.mdb"
Set conn = Server.CreateObject("ADODB.Connection"
conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & path & ";"
Dim formtype
Dim id
Dim thefirst
Dim thelast
Dim thestate
Dim thecity
Dim theaddress
Dim thephone
Dim thezip
Dim theemail
formtype = Request.Form("formtype"
thefirst = Replace(Request.Form("first"
thelast = Replace(Request.Form("last"
thestate = Replace(Request.Form("state"
thecity = Replace(Request.Form("city"
theaddress = Replace(Request.Form("address"
thephone = Replace(Request.Form("phone"
thezip = Replace(Request.Form("zip"
theemail = Replace(Request.Form("email"
Dim query
Set query = conn.Execute("INSERT INTO demo_table (first, last, address, city, state, zip, email, phone) VALUES ('" & thefirst & "', '" & thelast & "', '" & theaddress & "', '" & thecity & "', '" & thestate & "', '" & thezip & "', '" & theemail & "', '" & thephone & "')"
conn.Close
Set conn = Nothing
Response.Redirect "/demo/demo_view.asp"
%>
----------------------------------------------------------
Here is a link to my access database on a testing server...