View Single Post
  #1 (permalink)  
Old 02-15-05, 02:48 AM
braveheart braveheart is offline
New Member
 
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
form to database

is there anyone that could help me trace the problem with this code? i actually downloaded this source code from codefixer site but it seems its not working with my computer and im not even sure if it has something to do with dsn-less connection or something i don't know. please help... i'm just a newbie when it comes to database so i would greatly appreciate any inputs from anyone. thanks.

form.html contains-
<html>
<head>
<title>Form to Database</title>
</head>

<body>
<!-- comment - start the HTML form and use a HTML table for formatting-->
<form name="form1" action="add_to_database.asp" method="post">
<div align="center">
<table width="80%" border="0">
<tr>
<td>Name :</td>
<td><input type="text" name="name"></td>
</tr>
<tr>
<td>Email :</td>
<td> <input type="text" name="email"></td>
</tr>
<tr>
<td>Comments :</td>
<td><textarea name="comments"></textarea></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" value="submit details" name="submit"></td>
</tr>
</table>
</div>
</form>
<!-- end the HTML form-->
</body>
</html>

add_to_database.asp contains -

<% @ 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 users_tbl (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("Users.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>

showrecords.asp contains -

<% @ Language="VBScript" %>
<% Option Explicit %>
<html>
<head>
<title>Form to database - showing records</title>
</head>
<body>
<%
'declare your variables
Dim connection, recordset
Dim sSQL, sConnString

'declare SQL statement that will query the database
sSQL="SELECT * FROM Users_tbl"

'create an ADO connection and recordset object
Set connection = Server.CreateObject("ADODB.connection")
Set recordset = Server.CreateObject("ADODB.Recordset")

'define the connection string, specify database
'driver and the location of database
sConnString="PROVIDER=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=" & Server.MapPath("Users.mdb")

'Open the connection to the database
Connection.Open sConnString

'Open the recordset object, executing the SQL
Recordset.Open sSQL, Connection

'Looping through the records until the end of the records
Do while Not recordset.eof
Response.Write "Name : " & recordset("name") & "<br>"
Response.Write "Email : " & recordset("email") & "<br>"
Response.Write "Comments : " & recordset("comments") & "<br><br>"
'move on to the next record
recordset.MoveNext
loop

'Now close the recordset and the connection object
recordset.Close
Set recordset = Nothing
connection.Close
Set connection = Nothing
%>
</body>
</html>

and of course the users.mdb which i created using microsoft access 2000. it contains an id, name, email and comments with the name of table as users_tbl.

thanks very much.
Reply With Quote