putting form data into a database

Results 1 to 2 of 2

Thread: putting form data into a database

  1. #1
    Join Date
    Dec 1969

    Default putting form data into a database

    I am creating my first ASP application. I have an ASP form that I created to take data entered by a visitor to my web site and put it into a database. When the visitor hits the submit button it is supposed to submit the data into the database. So I know I have this submit button code on my asp form page, but I have to put all of this other code about opening the connection and adding records to the database. Where do I put that code? In the asp form page? How does this connect with the action of the submit button being clicked? They seem independent right now and I don&#039;t see how hitting the submit button is going to trigger the code to put the info into the database. My submit button code looks like this:<BR><BR>&#060;BUTTON NAME="submit" VALUE="submit" TYPE="submit"&#062;&#060;IMG SRC="image.gif"&#062;&#060;/BUTTON&#062;<BR><BR>and the code for making the connection to the database and placing the data from the input form looks (in general) like this (thanks for the help with that also by the way, guys):<BR><BR>Set Connect = Server.CreateObject("ADODB.Connection")<BR>Connect .Open "test"<BR><BR>Set RS = Server.CreateObject("ADODB.Recordset")<BR>Query = "SELECT * FROM tablename"<BR>Rs.Open Query, Connect, 3, 3<BR>Rs.AddNew<BR>RS("LastName") = Request("LastName")<BR>Rs.Update<BR>Rs.Close<BR>Co nnect.Close<BR>Set Connect = Nothing<BR>Set RS = Nothing<BR><BR>So how do I connect these two? Thank you very much for your help!

  2. #2
    Join Date
    Dec 1969

    Default Time to get a *GOOD* book...

    ...but in the meantime, until you get to the bookstore, take a look at http://www.LearnASP.com and the "Database" lessons. Especially look at the "Full Cycle" example there, where he shows adding, displaying, and editing information in/from a database.<BR><BR>The short answer, by the way, is the SUBMIT button does *NOT* control this! It is the &#060;FORM...&#062; tag that controls what happens *WHEN* the SUBMIT button is pressed.<BR><BR>&#060;FORM Name="yourChoice" Method="Post" Action="whereTheInformationIsPostedTo.asp"&#062;<B R><BR>Note that you *can* post to the same ASP page! But then you have to have logic on the page that says "if I didn&#039;t get anything posted to me, then don&#039;t open the DB or try to do the update." Not that it&#039;s a bad idea to have such logic, even when using multiple pages. But maybe that&#039;s way too advanced for you at this stage.<BR><BR>SO...<BR><BR>*PLEASE* go get a GOOD book on ASP. You will save yourself SO much grief!<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts