I'm a newbie with inputing into a database. Can someone help me with the script below. There is probably a few errors. Can you spot them please :)

Thanks in advance


Dim conn, rsadd, sql
Set conn=Server.CreateObject("ADODB.Connection")
conn.Open "seneca_book_db"
Set rsadd=Server.CreateObject("ADODB.RecordSet")
sql="Select * From Customers"
rsadd.Open sql, conn
rsadd.AddNew
rsadd("Custaccount")=request("T3")
rsadd("Custname")=request("T3")
rsadd("Custadd")=request("T5")
rsadd("Custcity")=request("T6")
rsadd("Custpostal")=request("T7")
rsadd("Custpassword")=request("T2")
rsadd("Custemail")=Lcase(request("T4"))
rsadd.Update
rsadd.MoveFirst
rsadd.close
Set rsadd = Nothing

Recommended Answers

All 3 Replies

Where to start. First conceptually this looks like some e-commerce project, you are storing customer details.

1. Conceptually: You are in danger of creating an uncohesive and tightly coupled system, (I have one of these scripted just as you are showing, don't make my mistake) the next project you do you will have to code this stuff all again, get it right now and you will already have written 50% of your next project. Read up on classes for vbscript, its a great medium for learning these concepts without the worries of inheritance/overloading and polymorphism that VBScript doesn't support anyway. You'll also need to know about Server Side incudes or SSI's <!--#include file="somefile.asp" --> these allow you to keep VBScript in seperate ASP files and include that code at the top of other .asp files. If you don't want to feel bored when you right Set Con = ServerCreateObject blah... for the 100th time this is the way to go.


2. Nitty Griity: the default recordset is a read only forward only cursor so you won't be able to apply the update. Read up on ADO recordsets there is heaps on the internet (TIP: put -.NET in the search engine box to avoid the proliferation of ASP.NET stuff)

3. Maintainability: Read up on Global.asa Put the connection string "seneca_book_db" into your global.asa file in the Application_OnStart sub as a key/value pair.

Application("ConnectionString") = "seneca_book_db"

Otherwise at deploy time you are gonna be updating a lot of pages...
open, select connection string, paste new connection string, next page ....snore ZZZZZZZZZZZ

My way you just set it one time in global.asa, job done home early!

Thanks a lot for you help. :)


Jason

Hey no problem.

I was a bit worried I had rambled on about a load of stuff. I'm going to do a series of articles in the ASP tutorial section, I've posted part one already.

I'll make sure updateable recordsets get included in there somewhere in part 3 perhaps.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.