PDA

View Full Version : form field to databse help.



greenelephant
03 Aug 2009, 05:41 PM
Hi there everyone

I have a web page with form field on with entry fields for name, email address and comments. I want to save those details to a MS access database using asp here is HTML form code





<head>
<meta http-equiv="Content-Language" content="en-gb">
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>FEEDBACK FORM</title>
<link rel="stylesheet" type="text/css" href="navbar.css">
</head>

<body>

<p>FEEDBACK FORM</p>
<p>&nbsp;</p>
<form name =form1" method="POST" action="feedbackform.asp">
<p>&nbsp;</p>
<table border="0" width="100%" id="table1">
<tr>
<td>
<p align="right">NAME</td>
<td><input type="text" name="name" size="20"></td>
</tr>
<tr>
<td>
&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td>
<p align="right">EMAIL ADDRESS</td>
<td><input type="text" name="email" size="20"></td>
</tr>
<tr>
<td valign="top">
&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td valign="top">
<p align="right">COMMENTS</td>
<td><textarea rows="8" name="comments" cols="24"></textarea></td>
</tr>
<tr>
<td valign="top">
&nbsp;</td>
<td>&nbsp;</td>
</tr>
<tr>
<td valign="top">
&nbsp;</td>
<td><input type="submit" value="Submit" name="submit"><input type="reset" value="Reset" name="reset"></td>
</tr>
</table>
<p align="center">&nbsp;</p>
</form>
<p>&nbsp;</p>

</body>



and next is ASP code



<%@ Language="VBScript" %>
<% Option Explicit %>
<html>
<head>
<title>Form to database</title>
</head>
<body>
<%
'declare your variables
Dim name, email, comments
Dim sConnString, connection, sSQL
'Receiving values from Form, assign the values entered to variables
name = Request.Form("name")
email = Request.Form("email")
comments =Request.Form("comments")

'declare SQL statement that will query the database
sSQL = "INSERT into feedback (name, email, comments) values ('" & _
name & "', '" & email & "', '" & comments & "')"
'define the connection string, specify database
'driver and the location of database
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("feedback.mdb")
'create an ADO connection object
Set connection = Server.CreateObject("ADODB.Connection")

'Open the connection to the database
connection.Open(sConnString)

'execute the SQL
connection.execute(sSQL)

response.write "The form information was inserted successfully."
'Done. Close the connection object
connection.Close
Set connection = Nothing
%>
</body>
</html>



now for some reason this code isnt working. I am stuck and need your help. Does anyone know what to do?

Thank you

:rainbow: