Inserting Rows into a Database

Inserting Rows into a DatabaseThis tutorial will show you how to insert a rowof data into a database using ASP and an MS Access database. You can doit on one ASP file, but we'll have two files: one processor page(proc.asp), and one form page (form.asp). Then, we'll make the MSAccess database that corresponds to the ASP.

Part I - Creating the processing page: proc.asp
This page will catch the form data, open a connection with the Accessdatabase (change "test.mdb" to your database), insert the row using asql query, and close the connection. If it executes fine, it will printout "done inserting row".
Here's the code:

<%Dim ConnDim SqlTempIf request("insrow") = "1" THENpsubject = request("pSubj")pdate = request("pDate")ptext = request("pText")Set Conn = Server.CreateObject("ADODB.Connection")Conn.connectionstring = 	"Provider=Microsoft.Jet.OLEDB.4.0;Data 	Source=" & Server.MapPath("test.mdb")& ";" Conn.Open SQLTemp = "INSERT INTO tblTest (pSubj, pDate, pText) 	VALUES ('" & psubject & "', " & pdate & ",	'" & ptext & "')"Conn.execute(SQLTemp)Conn.CloseSet Conn = Nothingresponse.write("<p>done inserting row</p>")End If%>

Part II - Creating the form: form.asp
Here's a simple form that will use the "post" method to submit the info to the proc.asp page:

<form name="frmInsert" method="post" action="test.asp"><input type="hidden" name="insrow" value="1">Subject: <input type="text" name="pSubj" size="13"><br>Date: <input type="text" name="pDate" size="13"><br>Text: <input type="text" name="pText" size="13"><br><input type="submit" size=8 value="Submit"></form>
Part III - creating the database: test.mdb
Make a table inthe database called "tblTest" (you may change it, but make sure itcorresponds with the above table name). Inside the database, make anAutonumber row called "pSubj" which is the Primary Key, a date rowcalled "pDate", and a row called "pText" with the memo row-type.
And there you have it, a database, a form, and a processor ready for data entry!
Note:Had trouble connecting to the database? Click here.

Related Articles

  • Alternating Rows: Mysql
    The first thing we need to do is connect to the database. I always put my db connection in a universal file, that way I can just change the variables once if I need to; but for the sake of the tutorial, im putting it in this file.
  • MySQL Tables
    Create, insert, update, delete, count and select rows in a database.
  • Alternating Row Colors
    Theres two different ways this can be done. The first is by getting results from a mysql query, the second is going through the values of an array. Ill go over both. First the full files (ill break it up into two files, one using mysql, and one using an array)
  • Design an Online Chat Room with PHP and MySQL
    In this article, you will learn how to design and develop a simple online chat room with PHP and MySQL. This tutorial explains every steps of the development, including both database design and PHP programming. Basic computer skills and knowledge of HTML and PHP are required. Ok, lets begin now. ....
  • Alternating Rows: Arrays
    The first thing we do here is echo out the html, again I wont go over this because theres really nothing to explain, except the css. We have two css classes, one for each of the alternating rows.
  • PHP News CMS
    Check out this great tutorial to find out all the details of Content Management Systems (CMS). Everything you need to know is right here.
  • Users Online
    First Run this SQL In your MYSQL database..
  • Image Databasing
    This tutorial teaches you how to upload images into a mysql database using PHP. Even though it sounds complicated, it is fairly simple and has many practical applications. One example of an application would be Forum User Images...
  • PHP User Stats
    In this tutorial I am going to teach you how to make a User Stats menu in PHP and MySQL which displays: Unique hits, Unique hits today, Total hits, Total hits today. If you dont have MySQL you can get one for free here.
  • Alternating Backgrounds
    Alternate the backgrounds of table rows displayed from a MySQL database.

Contact Web Design Outsource and get started today

Need Website Designing, Development, Redesigning, Maintenance and SEO services or help growing your company's web presence? Request a free Quote Now.