Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - inserting data
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

inserting data

 Post Reply Post Reply
Author
moseti View Drop Down
Newbie
Newbie
Avatar

Joined: 18 January 2007
Location: Kenya
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote moseti Quote  Post ReplyReply Direct Link To This Post Topic: inserting data
    Posted: 18 January 2007 at 12:59pm
Hi,
I have written code that inserts data into a database. Problem is that when the data is inserted, several blank records(2-3) are also inserted into the database. i pulled the tutorial off Web Wiz.

Can any body help
Confused
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 18 January 2007 at 2:22pm
Sure. You are doing something wrong Geek
 
No, but in all seriousness. We cannot really help without knowing what you are doing. Show us some code.
Back to Top
moseti View Drop Down
Newbie
Newbie
Avatar

Joined: 18 January 2007
Location: Kenya
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote moseti Quote  Post ReplyReply Direct Link To This Post Posted: 19 January 2007 at 11:57am

The code that that i am using is as follows


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/myConn.asp" -->
<%
Dim rsDetails
Dim rsDetails_numRows

Set rsDetails = Server.CreateObject("ADODB.Recordset")
rsDetails.ActiveConnection = MM_myConn_STRING
rsDetails.Source = "SELECT * FROM tblComments"
rsDetails.CursorType = 2
rsDetails.CursorLocation = 2
rsDetails.LockType = 3
rsDetails.Open()

rsDetails.Addnew
rsDetails.Fields("Name") = Request.Form("name")
rsDetails.Fields("Comments") = Request.Form("comments")
rsDetails.Update

<!--rsDetails_numRows = 0 -->
%>


Back to Top
bootcom View Drop Down
Senior Member
Senior Member
Avatar

Joined: 26 February 2005
Location: United Kingdom
Status: Offline
Points: 259
Post Options Post Options   Thanks (0) Thanks(0)   Quote bootcom Quote  Post ReplyReply Direct Link To This Post Posted: 20 January 2007 at 12:05pm
Could you post the code from the form too please, I think I see whats going on here ... multiple form elements with the same name attribute
Back to Top
Freon22 View Drop Down
Groupie
Groupie


Joined: 04 December 2005
Status: Offline
Points: 42
Post Options Post Options   Thanks (0) Thanks(0)   Quote Freon22 Quote  Post ReplyReply Direct Link To This Post Posted: 22 January 2007 at 5:50pm
Not sure why you are doing a select statement. Anyways there are a few ways that you can insert into your database. When I was doing vbscript the first one I liked the best. I could run what I was inserting through a filter to make sure it was clean.
 
I am putting in the database connection so you make want to remove that part. I see you have an include file for you connection.
 

Dim objConn, strSQL
 
'Create the insert statement
strSQL = "INSERT INTO tblComments(Name, Comments) VALUES ('" & Request.Form("Name") & "', '" & Request.Form("Comments") & "')"
 
Set objConn = Server.CreateObject("ADODB.Connection")
 
objConn.ConnectionString= "Driver={Microsoft Access Driver(*.mdb)};" & _
"DBQ=" & Server.MapPath("db/yourdatabasename/mdb") 
 
'Open the connection
objConn.Open
 
'Execute the insert
objConn.Execute strSQL
 
'Close the database connection and set it to nothing
objConn.Close
Set objConn = Nothing
 
Another way is same as you are doing.

Dim objConn, objRS
 
Set objConn = Server.CreateObject("ADODB.Connection")
 
objConn.ConnectionString= "Driver={Microsoft Access Driver(*.mdb)};" & _
"DBQ=" & Server.MapPath("db/yourdatabasename/mdb") 
 
'Open the connection
objConn.Open
 
'Create a recordset
Set objRS = Server.CreateObject("ADODB.Recordset")
 
objRS.Open "tblComments", objConn, adOpenStatic, adLockOptimistic
 
'Add the new record to the database table
 
objRS.AddNew
 
objRS("Name") = Request.Form("Name")
objRS("Comments") = Request.Form("Comments")
 
objRS.Update
 
'Alway close your recordset and connection
objRS.Close
Set objRS = Nothing
objConn.Close
Set objConn = Nothing
Hope this helps
Back to Top
MadDog View Drop Down
Mod Builder Group
Mod Builder Group
Avatar

Joined: 01 January 2002
Status: Offline
Points: 3008
Post Options Post Options   Thanks (0) Thanks(0)   Quote MadDog Quote  Post ReplyReply Direct Link To This Post Posted: 23 January 2007 at 2:06am
Originally posted by moseti moseti wrote:


The code that that i am using is as follows


<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/myConn.asp" -->
<%
Dim rsDetails
Dim rsDetails_numRows

Set rsDetails = Server.CreateObject("ADODB.Recordset")
rsDetails.ActiveConnection = MM_myConn_STRING
rsDetails.Source = "SELECT * FROM tblComments"
rsDetails.CursorType = 2
rsDetails.CursorLocation = 2
rsDetails.LockType = 3
rsDetails.Open()

rsDetails.Addnew
rsDetails.Fields("Name") = Request.Form("name")
rsDetails.Fields("Comments") = Request.Form("comments")
rsDetails.Update

<!--rsDetails_numRows = 0 -->
%>




Are you sure you got that tutorial from this website? Bruce (aka -boRg-) doesnt code like that (that is VERY dirty code!!!).
Back to Top
moseti View Drop Down
Newbie
Newbie
Avatar

Joined: 18 January 2007
Location: Kenya
Status: Offline
Points: 3
Post Options Post Options   Thanks (0) Thanks(0)   Quote moseti Quote  Post ReplyReply Direct Link To This Post Posted: 23 January 2007 at 1:01pm

Sorry, I have been away for some time. U asked for the form i have been using. The Code is as follows.

'Code for form

<form id="form1" name="form1" method="post" action="add_to_guestbook II.asp">
Name: 
  <input type="text" name="name" maxlength="20">
<br />
Comments: <input type="text" name="comments" maxlength="50">
     <input type="submit" name="Submit" value="Submit">
</form>

'tis but a simple form. As u can see from the previous code I had submitted, I am using - Request.Form("name") to read values from the name textbox.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.