Current location: Hot Scripts Forums » Programming Languages » ASP » form to database


form to database

Reply
  #1 (permalink)  
Old 02-15-05, 03: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.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-25-05, 10:24 AM
hesiod's Avatar
hesiod hesiod is offline
Newbie Coder
 
Join Date: Feb 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Well, I don't know about your exact situation and I have not used JET with an access database, but I don't think you need to do "connection.Open(sConnString)" first. The execute statement should do all the opening and inserting for you. You will still need to close it when done (as you have in your code). Try commenting out that line and try again.

(This does not apply to reading the DB -- you must open the connection when using recordsets, just like you have)

If that does not work, you can always try using a slightly different connection method. Try using a different DB driver:
sConnString ="DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("Users.mdb")

Do you have one of Win2K Pro, 2k3 server, or XP pro? Just making sure, I assume you do. Do you have Office installed? I know the JET driver didn't work for me on Excel files unless excel or office was installed.

I can't see any actual errors in the code, though. Does it give you any errors, like type mismatch or anything? You're not trying to enter a string longer than the DB can handle, right? I think Text is max 50 chars & Memo is 255 chars by default.

Hope I was helpful!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 03-01-05, 11:12 PM
braveheart braveheart is offline
New Member
 
Join Date: Feb 2005
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
still not working

still not working
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 03-09-05, 06:17 AM
GO4TF4CE's Avatar
GO4TF4CE GO4TF4CE is offline
Wannabe Coder
 
Join Date: Apr 2004
Posts: 223
Thanks: 0
Thanked 0 Times in 0 Posts
Question

What is the exact error message?

if you provide me with that I'll try to help a bit more.

GO4TF4CE

Last edited by GO4TF4CE; 03-09-05 at 06:20 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Form with database mattman1281 ASP 7 07-23-04 08:38 PM
Form with database mattman1281 PHP 2 07-06-04 05:54 PM
How do i search from a form to mysql database using php QTortZ PHP 6 06-02-04 10:57 PM
How do I get line breaks to carry over from form to database? Poodle Tosser PHP 3 03-31-04 08:50 AM
SQL database registration form help vinhkhuong PHP 3 10-10-03 04:49 AM


All times are GMT -5. The time now is 11:50 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.